Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(api-graphql): Bump graphql to 14.5.0 #8984

Merged
merged 13 commits into from Oct 26, 2021
2 changes: 1 addition & 1 deletion packages/api-graphql/package.json
Expand Up @@ -49,7 +49,7 @@
"@aws-amplify/cache": "4.0.21",
"@aws-amplify/core": "4.3.1",
"@aws-amplify/pubsub": "4.1.11",
"graphql": "14.0.0",
"graphql": "14.5.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using graphql@15.6.0?

"uuid": "^3.2.1",
"zen-observable-ts": "0.8.19"
},
Expand Down
13 changes: 7 additions & 6 deletions packages/api-graphql/src/GraphQLAPI.ts
Expand Up @@ -12,7 +12,7 @@
*/
import { GraphQLError } from 'graphql/error/GraphQLError';
// @ts-ignore
import { OperationDefinitionNode } from 'graphql/language';
import { DocumentNode, OperationDefinitionNode } from 'graphql/language';
wlee221 marked this conversation as resolved.
Show resolved Hide resolved
import { print } from 'graphql/language/printer';
import { parse } from 'graphql/language/parser';
import Observable from 'zen-observable-ts';
Expand Down Expand Up @@ -203,9 +203,10 @@ export class GraphQLAPIClass {
*/
getGraphqlOperationType(operation) {
const doc = parse(operation);
const {
definitions: [{ operation: operationType }],
} = doc;
const definitions = doc.definitions as ReadonlyArray<
OperationDefinitionNode
>;
const [{ operation: operationType }] = definitions;
Comment on lines -206 to +211
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so confident with this one. It seems that doc.definitions doesn't always contain an object with operation field. You can check out its typing here: https://github.com/graphql/graphql-js/blob/7b389be745eaeda2a4f9ca33a3db93717f21447e/tstypes/language/ast.d.ts#L186-L195

OperationDefinitionNode is the one that had it, so I casted definitions to it.

Copy link
Contributor Author

@wlee221 wlee221 Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: I found that @types/graphql@14.0.0 has the same type, so this is not a change from 14.0.0 -> 14.5.0.


return operationType;
}
Expand Down Expand Up @@ -294,7 +295,7 @@ export class GraphQLAPIClass {
};

const body = {
query: print(query),
query: print(query as DocumentNode),
Copy link
Contributor Author

@wlee221 wlee221 Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to address "Type 'string' is not assignable to type 'ASTNode'." error.

I'm confident that this query is always of type DocumentNode, because query is always run through parsing here before _graphql function is called:

const query =
typeof paramQuery === 'string'
? parse(paramQuery)
: parse(print(paramQuery));

in which parse returns DocumentNode object (source).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either we can do as DocumentNode here, or we can create an internal type

const ParsedGraphQLOption = Omit<GraphQLOptions, 'query'> & {query: DocumentNode}

but I kept it simple for now. Opinions welcome!

variables,
};

Expand Down Expand Up @@ -389,7 +390,7 @@ export class GraphQLAPIClass {
appSyncGraphqlEndpoint,
authenticationType,
apiKey,
query: print(query),
query: print(query as DocumentNode),
region,
variables,
graphql_headers,
Expand Down