Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
fix(ci): fix types
Browse files Browse the repository at this point in the history
tsc must run successfully for both graphql v14 and v15
  • Loading branch information
yaacovCR committed Feb 17, 2020
1 parent b0241b7 commit 459ddfe
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ install:
- npm install graphql@$GRAPHQL_CHANNEL

script:
- if [ $GRAPHQL_CHANNEL == 'rc' ];
then npm test && npm run lint && npm run prettier-check;
else npm test;
fi
- npm test
- npm run coverage
- coveralls < ./coverage/lcov.info || true # if coveralls doesn't have it covered

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"compile": "tsc",
"pretest": "npm run clean && npm run compile",
"test": "npm run testonly",
"posttest": "npm run lint && npm run prettier:check",
"lint": "eslint --ext .js,.ts src",
"lint:watch": "esw --watch --cache --ext .js,.ts src",
"watch": "tsc -w",
Expand All @@ -21,7 +22,7 @@
"prepublishOnly": "npm run compile",
"prettier": "prettier --trailing-comma all --single-quote --write src/**/*.ts",
"prettier:check": "prettier --trailing-comma all --single-quote --check src/**/*.ts",
"prerelease": "npm test && npm run lint && npm run prettier:check",
"prerelease": "npm test",
"release": "npm run releaseonly",
"releaseonly": "standard-version"
},
Expand Down Expand Up @@ -83,7 +84,7 @@
"eslint-watch": "^6.0.1",
"express": "^4.17.1",
"express-graphql": "^0.9.0",
"graphql": "^15.0.0-rc.2",
"graphql": "^14.6.0",
"graphql-subscriptions": "^1.1.0",
"graphql-type-json": "^0.3.1",
"graphql-upload": "^9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/generate/extendResolversFromInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function extendResolversFromInterfaces(
type instanceof GraphQLObjectType ||
(versionInfo.major >= 15 && type instanceof GraphQLInterfaceType)
) {
const interfaceResolvers = type
const interfaceResolvers = (type as GraphQLObjectType)
.getInterfaces()
.map(iFace => resolvers[iFace.name]);
extendedResolvers[typeName] = Object.assign(
Expand Down
7 changes: 4 additions & 3 deletions src/stitching/mergeSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ function merge(
}, []),
});
} else if (initialCandidateType instanceof GraphQLInterfaceType) {
return new GraphQLInterfaceType({
const config = {
name: typeName,
fields: candidates.reduce(
(acc, candidate) => ({
Expand All @@ -365,12 +365,13 @@ function merge(
interfaces:
versionInfo.major >= 15
? candidates.reduce((acc, candidate) => {
const interfaces = (candidate.type as GraphQLInterfaceType).toConfig()
const interfaces = (candidate.type as GraphQLObjectType).toConfig()
.interfaces;
return interfaces != null ? acc.concat(interfaces) : acc;
}, [])
: undefined,
});
};
return new GraphQLInterfaceType(config);
} else if (initialCandidateType instanceof GraphQLUnionType) {
return new GraphQLUnionType({
name: typeName,
Expand Down
14 changes: 8 additions & 6 deletions src/stitching/typeFromAST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function typeFromAST(
}

function makeObjectType(node: ObjectTypeDefinitionNode): GraphQLObjectType {
return new GraphQLObjectType({
const config = {
name: node.name.value,
fields: () => makeFields(node.fields),
interfaces: () =>
Expand All @@ -79,19 +79,20 @@ function makeObjectType(node: ObjectTypeDefinitionNode): GraphQLObjectType {
) as GraphQLInterfaceType,
),
description: getDescription(node, backcompatOptions),
});
};
return new GraphQLObjectType(config);
}

function makeInterfaceType(
node: InterfaceTypeDefinitionNode,
): GraphQLInterfaceType {
return new GraphQLInterfaceType({
const config = {
name: node.name.value,
fields: () => makeFields(node.fields),
interfaces:
versionInfo.major >= 15
? () =>
node.interfaces.map(
((node as unknown) as ObjectTypeDefinitionNode).interfaces.map(
iface =>
createNamedStub(
iface.name.value,
Expand All @@ -100,8 +101,9 @@ function makeInterfaceType(
)
: undefined,
description: getDescription(node, backcompatOptions),
resolveType: parent => resolveFromParentTypename(parent),
});
resolveType: (parent: any) => resolveFromParentTypename(parent),
};
return new GraphQLInterfaceType(config);
}

function makeEnumType(node: EnumTypeDefinitionNode): GraphQLEnumType {
Expand Down
10 changes: 7 additions & 3 deletions src/utils/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
GraphQLSchema,
GraphQLUnionType,
versionInfo,
GraphQLInterfaceTypeConfig,
} from 'graphql';

import { healTypes } from './heal';
Expand All @@ -26,12 +27,15 @@ export function cloneType(type: GraphQLNamedType): GraphQLNamedType {
interfaces: config.interfaces.slice(),
});
} else if (type instanceof GraphQLInterfaceType) {
const config = type.toConfig();
return new GraphQLInterfaceType({
const config = ((type as unknown) as GraphQLObjectType).toConfig();
const newConfig = {
...config,
interfaces:
versionInfo.major >= 15 ? config.interfaces.slice() : undefined,
});
};
return new GraphQLInterfaceType(
(newConfig as unknown) as GraphQLInterfaceTypeConfig<any, any>,
);
} else if (type instanceof GraphQLUnionType) {
const config = type.toConfig();
return new GraphQLUnionType({
Expand Down
4 changes: 2 additions & 2 deletions src/utils/heal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function healTypes(
}

function healInterfaces(type: GraphQLObjectType | GraphQLInterfaceType) {
updateEachKey(type.getInterfaces(), iface => {
updateEachKey((type as GraphQLObjectType).getInterfaces(), iface => {
const healedType = healType(iface) as GraphQLInterfaceType;
return healedType;
});
Expand Down Expand Up @@ -217,7 +217,7 @@ function pruneTypes(
namedType instanceof GraphQLObjectType ||
(versionInfo.major >= 15 && namedType instanceof GraphQLInterfaceType)
) {
each(namedType.getInterfaces(), iface => {
each((namedType as GraphQLObjectType).getInterfaces(), iface => {
implementedInterfaces[iface.name] = true;
});
}
Expand Down

0 comments on commit 459ddfe

Please sign in to comment.