Skip to content

Commit

Permalink
Update graphql to version 14 (#624)
Browse files Browse the repository at this point in the history
Update graphql package + types.
Resolve typescript errors and update snapshots.

Fixes #626

-- Amending commit for a new hash for testing purposes
  • Loading branch information
trevor-scheer committed Oct 12, 2018
1 parent 11fc68a commit ac39108
Show file tree
Hide file tree
Showing 23 changed files with 100 additions and 186 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@types/babel-types": "^7.0.4",
"@types/chai": "^4.1.4",
"@types/common-tags": "^1.4.0",
"@types/graphql": "^0.13.4",
"@types/graphql": "^14.0.2",
"@types/inflected": "^1.1.29",
"@types/jest": "^23.3.1",
"@types/listr": "^0.13.0",
Expand All @@ -64,7 +64,7 @@
"@types/ws": "^6.0.0",
"chai": "^4.1.2",
"fs-monkey": "^0.3.3",
"graphql": "^0.13.2",
"graphql": "^14.0.2",
"husky": "^0.14.3",
"jest": "^23.5.0",
"jest-matcher-utils": "^23.5.0",
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-codegen-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"clean": "rm -rf lib",
"prebuild": "npm run clean",
"build": "tsc",
"watch": "tsc -w",
"prepare": "npm run build"
},
"engines": {
Expand Down
11 changes: 4 additions & 7 deletions packages/apollo-codegen-core/src/utilities/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import {
SelectionSetNode,
FieldNode,
GraphQLField,
GraphQLList,
GraphQLNonNull,
DocumentNode,
DirectiveNode
DirectiveNode,
isListType,
isNonNullType
} from "graphql";

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

export function isList(type: GraphQLType): boolean {
return (
type instanceof GraphQLList ||
(type instanceof GraphQLNonNull && type.ofType instanceof GraphQLList)
);
return isListType(type) || (isNonNullType(type) && isListType(type.ofType));
}

export function isMetaFieldName(name: string) {
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-codegen-flow-legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"clean": "rm -rf lib",
"prebuild": "npm run clean",
"build": "tsc",
"watch": "tsc -w",
"prepare": "npm run build"
},
"engines": {
Expand Down
22 changes: 9 additions & 13 deletions packages/apollo-codegen-flow-legacy/src/codeGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import {
isCompositeType,
isAbstractType,
GraphQLEnumType,
GraphQLList,
GraphQLNonNull,
GraphQLInputObjectType,
GraphQLObjectType,
GraphQLUnionType
GraphQLUnionType,
isListType,
isNonNullType
} from "graphql";

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

function getObjectTypeName(type: GraphQLType): string {
if (type instanceof GraphQLList) {
if (isListType(type)) {
return getObjectTypeName(type.ofType);
}
if (type instanceof GraphQLNonNull) {
if (isNonNullType(type)) {
return getObjectTypeName(type.ofType);
}
if (type instanceof GraphQLObjectType) {
Expand Down Expand Up @@ -355,17 +356,12 @@ export function propertyFromField(
const typeName = typeNameFromGraphQLType(context, fieldType);
let isArray = false;
let isArrayElementNullable = null;
if (fieldType instanceof GraphQLList) {
if (isListType(fieldType)) {
isArray = true;
isArrayElementNullable = !(fieldType.ofType instanceof GraphQLNonNull);
} else if (
fieldType instanceof GraphQLNonNull &&
fieldType.ofType instanceof GraphQLList
) {
isArrayElementNullable = !isNonNullType(fieldType.ofType);
} else if (isNonNullType(fieldType) && isListType(fieldType.ofType)) {
isArray = true;
isArrayElementNullable = !(
fieldType.ofType.ofType instanceof GraphQLNonNull
);
isArrayElementNullable = !isNonNullType(fieldType.ofType.ofType);
}
return {
...property,
Expand Down
10 changes: 5 additions & 5 deletions packages/apollo-codegen-flow-legacy/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
GraphQLFloat,
GraphQLBoolean,
GraphQLID,
GraphQLList,
GraphQLNonNull,
GraphQLScalarType
GraphQLScalarType,
isListType,
isNonNullType
} from "graphql";
import { LegacyCompilerContext } from "apollo-codegen-core/lib/compiler/legacyIR";
import { GraphQLType } from "graphql";
Expand All @@ -25,12 +25,12 @@ export function typeNameFromGraphQLType(
bareTypeName?: string | null,
nullable = true
): string {
if (type instanceof GraphQLNonNull) {
if (isNonNullType(type)) {
return typeNameFromGraphQLType(context, type.ofType, bareTypeName, false);
}

let typeName;
if (type instanceof GraphQLList) {
if (isListType(type)) {
typeName = `Array< ${typeNameFromGraphQLType(
context,
type.ofType,
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-codegen-flow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"clean": "rm -rf lib",
"prebuild": "npm run clean",
"build": "tsc",
"watch": "tsc -w",
"prepare": "npm run build"
},
"engines": {
Expand Down
12 changes: 6 additions & 6 deletions packages/apollo-codegen-flow/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {
GraphQLFloat,
GraphQLInt,
GraphQLID,
GraphQLList,
GraphQLNonNull,
GraphQLScalarType,
GraphQLString,
GraphQLType
GraphQLType,
isListType,
isNonNullType
} from "graphql";

import * as t from "@babel/types";
Expand Down Expand Up @@ -37,7 +37,7 @@ export function createTypeAnnotationFromGraphQLTypeFunction(
type: GraphQLType,
typeName?: string
): t.FlowTypeAnnotation {
if (type instanceof GraphQLList) {
if (isListType(type)) {
return t.genericTypeAnnotation(
t.identifier(arrayType),
t.typeParameterInstantiation([
Expand All @@ -58,7 +58,7 @@ export function createTypeAnnotationFromGraphQLTypeFunction(
} else {
return t.anyTypeAnnotation();
}
} else if (type instanceof GraphQLNonNull) {
} else if (isNonNullType(type)) {
// This won't happen; but for TypeScript completeness:
return typeAnnotationFromGraphQLType(type.ofType, typeName);
} else {
Expand All @@ -70,7 +70,7 @@ export function createTypeAnnotationFromGraphQLTypeFunction(
type: GraphQLType,
typeName?: string
): t.FlowTypeAnnotation {
if (type instanceof GraphQLNonNull) {
if (isNonNullType(type)) {
return nonNullableTypeAnnotationFromGraphQLType(type.ofType, typeName);
} else {
return t.nullableTypeAnnotation(
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-codegen-scala/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"clean": "rm -rf lib",
"prebuild": "npm run clean",
"build": "tsc",
"watch": "tsc -w",
"prepare": "npm run build"
},
"engines": {
Expand Down
10 changes: 5 additions & 5 deletions packages/apollo-codegen-scala/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
GraphQLFloat,
GraphQLBoolean,
GraphQLID,
GraphQLList,
GraphQLNonNull,
GraphQLScalarType,
GraphQLEnumType,
isAbstractType
isAbstractType,
isNonNullType,
isListType
} from "graphql";
import { LegacyCompilerContext } from "apollo-codegen-core/lib/compiler/legacyIR";
import { GraphQLType } from "graphql";
Expand Down Expand Up @@ -39,7 +39,7 @@ export function typeNameFromGraphQLType(
isOptional?: boolean,
isInputObject?: boolean
): string {
if (type instanceof GraphQLNonNull) {
if (isNonNullType(type)) {
return typeNameFromGraphQLType(
context,
type.ofType,
Expand All @@ -51,7 +51,7 @@ export function typeNameFromGraphQLType(
}

let typeName;
if (type instanceof GraphQLList) {
if (isListType(type)) {
typeName =
"Seq[" +
typeNameFromGraphQLType(context, type.ofType, bareTypeName) +
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-codegen-swift/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"clean": "rm -rf lib",
"prebuild": "npm run clean",
"build": "tsc",
"watch": "tsc -w",
"prepare": "npm run build"
},
"engines": {
Expand Down
11 changes: 5 additions & 6 deletions packages/apollo-codegen-swift/src/codeGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
getNamedType,
isCompositeType,
GraphQLEnumType,
GraphQLList,
GraphQLNonNull,
GraphQLInputObjectType
GraphQLInputObjectType,
isNonNullType,
isListType
} from "graphql";

import {
Expand Down Expand Up @@ -221,9 +221,8 @@ export class SwiftAPIGenerator extends SwiftGenerator<CompilerContext> {
const properties = variables.map(({ name, type }) => {
const typeName = this.helpers.typeNameFromGraphQLType(type);
const isOptional = !(
type instanceof GraphQLNonNull ||
(type instanceof GraphQLList &&
type.ofType instanceof GraphQLNonNull)
isNonNullType(type) ||
(isListType(type) && isNonNullType(type.ofType))
);
return { name, propertyName: name, type, typeName, isOptional };
});
Expand Down
19 changes: 10 additions & 9 deletions packages/apollo-codegen-swift/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import {
GraphQLFloat,
GraphQLBoolean,
GraphQLID,
GraphQLList,
GraphQLNonNull,
GraphQLScalarType,
GraphQLEnumType,
isCompositeType,
getNamedType,
GraphQLInputField
GraphQLInputField,
isNonNullType,
isListType
} from "graphql";

import { camelCase, pascalCase } from "change-case";
Expand Down Expand Up @@ -49,7 +50,7 @@ export class Helpers {
unmodifiedTypeName?: string,
isOptional?: boolean
): string {
if (type instanceof GraphQLNonNull) {
if (isNonNullType(type)) {
return this.typeNameFromGraphQLType(
type.ofType,
unmodifiedTypeName,
Expand All @@ -60,7 +61,7 @@ export class Helpers {
}

let typeName;
if (type instanceof GraphQLList) {
if (isListType(type)) {
typeName =
"[" +
this.typeNameFromGraphQLType(type.ofType, unmodifiedTypeName) +
Expand All @@ -84,9 +85,9 @@ export class Helpers {
}

fieldTypeEnum(type: GraphQLType, structName: string): string {
if (type instanceof GraphQLNonNull) {
if (isNonNullType(type)) {
return `.nonNull(${this.fieldTypeEnum(type.ofType, structName)})`;
} else if (type instanceof GraphQLList) {
} else if (isListType(type)) {
return `.list(${this.fieldTypeEnum(type.ofType, structName)})`;
} else if (type instanceof GraphQLScalarType) {
return `.scalar(${this.typeNameForScalarType(type)}.self)`;
Expand Down Expand Up @@ -146,7 +147,7 @@ export class Helpers {

let type = field.type;

if (isConditional && type instanceof GraphQLNonNull) {
if (isConditional && isNonNullType(type)) {
type = type.ofType;
}

Expand Down Expand Up @@ -270,14 +271,14 @@ export class Helpers {
outputTypeName: string
): string {
let isOptional;
if (type instanceof GraphQLNonNull) {
if (isNonNullType(type)) {
isOptional = !!isConditional;
type = type.ofType;
} else {
isOptional = true;
}

if (type instanceof GraphQLList) {
if (isListType(type)) {
const elementType = type.ofType;
if (isOptional) {
return `${expression}.flatMap { ${makeClosureSignature(
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-codegen-typescript-legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"clean": "rm -rf lib",
"prebuild": "npm run clean",
"build": "tsc",
"watch": "tsc -w",
"prepare": "npm run build"
},
"engines": {
Expand Down
Loading

0 comments on commit ac39108

Please sign in to comment.