Skip to content

Commit ac39108

Browse files
committed
Update graphql to version 14 (#624)
Update graphql package + types. Resolve typescript errors and update snapshots. Fixes #626 -- Amending commit for a new hash for testing purposes
1 parent 11fc68a commit ac39108

23 files changed

Lines changed: 100 additions & 186 deletions

File tree

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@types/babel-types": "^7.0.4",
5151
"@types/chai": "^4.1.4",
5252
"@types/common-tags": "^1.4.0",
53-
"@types/graphql": "^0.13.4",
53+
"@types/graphql": "^14.0.2",
5454
"@types/inflected": "^1.1.29",
5555
"@types/jest": "^23.3.1",
5656
"@types/listr": "^0.13.0",
@@ -64,7 +64,7 @@
6464
"@types/ws": "^6.0.0",
6565
"chai": "^4.1.2",
6666
"fs-monkey": "^0.3.3",
67-
"graphql": "^0.13.2",
67+
"graphql": "^14.0.2",
6868
"husky": "^0.14.3",
6969
"jest": "^23.5.0",
7070
"jest-matcher-utils": "^23.5.0",

packages/apollo-codegen-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"clean": "rm -rf lib",
1717
"prebuild": "npm run clean",
1818
"build": "tsc",
19+
"watch": "tsc -w",
1920
"prepare": "npm run build"
2021
},
2122
"engines": {

packages/apollo-codegen-core/src/utilities/graphql.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import {
2121
SelectionSetNode,
2222
FieldNode,
2323
GraphQLField,
24-
GraphQLList,
25-
GraphQLNonNull,
2624
DocumentNode,
27-
DirectiveNode
25+
DirectiveNode,
26+
isListType,
27+
isNonNullType
2828
} from "graphql";
2929

3030
declare module "graphql/utilities/buildASTSchema" {
@@ -41,10 +41,7 @@ export function sortEnumValues(values: GraphQLEnumValue[]): GraphQLEnumValue[] {
4141
}
4242

4343
export function isList(type: GraphQLType): boolean {
44-
return (
45-
type instanceof GraphQLList ||
46-
(type instanceof GraphQLNonNull && type.ofType instanceof GraphQLList)
47-
);
44+
return isListType(type) || (isNonNullType(type) && isListType(type.ofType));
4845
}
4946

5047
export function isMetaFieldName(name: string) {

packages/apollo-codegen-flow-legacy/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"clean": "rm -rf lib",
1717
"prebuild": "npm run clean",
1818
"build": "tsc",
19+
"watch": "tsc -w",
1920
"prepare": "npm run build"
2021
},
2122
"engines": {

packages/apollo-codegen-flow-legacy/src/codeGeneration.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import {
44
isCompositeType,
55
isAbstractType,
66
GraphQLEnumType,
7-
GraphQLList,
87
GraphQLNonNull,
98
GraphQLInputObjectType,
109
GraphQLObjectType,
11-
GraphQLUnionType
10+
GraphQLUnionType,
11+
isListType,
12+
isNonNullType
1213
} from "graphql";
1314

1415
import { wrap } from "apollo-codegen-core/lib/utilities/printing";
@@ -187,10 +188,10 @@ export function interfaceVariablesDeclarationForOperation(
187188
}
188189

189190
function getObjectTypeName(type: GraphQLType): string {
190-
if (type instanceof GraphQLList) {
191+
if (isListType(type)) {
191192
return getObjectTypeName(type.ofType);
192193
}
193-
if (type instanceof GraphQLNonNull) {
194+
if (isNonNullType(type)) {
194195
return getObjectTypeName(type.ofType);
195196
}
196197
if (type instanceof GraphQLObjectType) {
@@ -355,17 +356,12 @@ export function propertyFromField(
355356
const typeName = typeNameFromGraphQLType(context, fieldType);
356357
let isArray = false;
357358
let isArrayElementNullable = null;
358-
if (fieldType instanceof GraphQLList) {
359+
if (isListType(fieldType)) {
359360
isArray = true;
360-
isArrayElementNullable = !(fieldType.ofType instanceof GraphQLNonNull);
361-
} else if (
362-
fieldType instanceof GraphQLNonNull &&
363-
fieldType.ofType instanceof GraphQLList
364-
) {
361+
isArrayElementNullable = !isNonNullType(fieldType.ofType);
362+
} else if (isNonNullType(fieldType) && isListType(fieldType.ofType)) {
365363
isArray = true;
366-
isArrayElementNullable = !(
367-
fieldType.ofType.ofType instanceof GraphQLNonNull
368-
);
364+
isArrayElementNullable = !isNonNullType(fieldType.ofType.ofType);
369365
}
370366
return {
371367
...property,

packages/apollo-codegen-flow-legacy/src/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {
44
GraphQLFloat,
55
GraphQLBoolean,
66
GraphQLID,
7-
GraphQLList,
8-
GraphQLNonNull,
9-
GraphQLScalarType
7+
GraphQLScalarType,
8+
isListType,
9+
isNonNullType
1010
} from "graphql";
1111
import { LegacyCompilerContext } from "apollo-codegen-core/lib/compiler/legacyIR";
1212
import { GraphQLType } from "graphql";
@@ -25,12 +25,12 @@ export function typeNameFromGraphQLType(
2525
bareTypeName?: string | null,
2626
nullable = true
2727
): string {
28-
if (type instanceof GraphQLNonNull) {
28+
if (isNonNullType(type)) {
2929
return typeNameFromGraphQLType(context, type.ofType, bareTypeName, false);
3030
}
3131

3232
let typeName;
33-
if (type instanceof GraphQLList) {
33+
if (isListType(type)) {
3434
typeName = `Array< ${typeNameFromGraphQLType(
3535
context,
3636
type.ofType,

packages/apollo-codegen-flow/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"clean": "rm -rf lib",
1717
"prebuild": "npm run clean",
1818
"build": "tsc",
19+
"watch": "tsc -w",
1920
"prepare": "npm run build"
2021
},
2122
"engines": {

packages/apollo-codegen-flow/src/helpers.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import {
33
GraphQLFloat,
44
GraphQLInt,
55
GraphQLID,
6-
GraphQLList,
7-
GraphQLNonNull,
86
GraphQLScalarType,
97
GraphQLString,
10-
GraphQLType
8+
GraphQLType,
9+
isListType,
10+
isNonNullType
1111
} from "graphql";
1212

1313
import * as t from "@babel/types";
@@ -37,7 +37,7 @@ export function createTypeAnnotationFromGraphQLTypeFunction(
3737
type: GraphQLType,
3838
typeName?: string
3939
): t.FlowTypeAnnotation {
40-
if (type instanceof GraphQLList) {
40+
if (isListType(type)) {
4141
return t.genericTypeAnnotation(
4242
t.identifier(arrayType),
4343
t.typeParameterInstantiation([
@@ -58,7 +58,7 @@ export function createTypeAnnotationFromGraphQLTypeFunction(
5858
} else {
5959
return t.anyTypeAnnotation();
6060
}
61-
} else if (type instanceof GraphQLNonNull) {
61+
} else if (isNonNullType(type)) {
6262
// This won't happen; but for TypeScript completeness:
6363
return typeAnnotationFromGraphQLType(type.ofType, typeName);
6464
} else {
@@ -70,7 +70,7 @@ export function createTypeAnnotationFromGraphQLTypeFunction(
7070
type: GraphQLType,
7171
typeName?: string
7272
): t.FlowTypeAnnotation {
73-
if (type instanceof GraphQLNonNull) {
73+
if (isNonNullType(type)) {
7474
return nonNullableTypeAnnotationFromGraphQLType(type.ofType, typeName);
7575
} else {
7676
return t.nullableTypeAnnotation(

packages/apollo-codegen-scala/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"clean": "rm -rf lib",
1717
"prebuild": "npm run clean",
1818
"build": "tsc",
19+
"watch": "tsc -w",
1920
"prepare": "npm run build"
2021
},
2122
"engines": {

0 commit comments

Comments
 (0)