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

Commit

Permalink
chore(upstream): graphql v15 support
Browse files Browse the repository at this point in the history
 - add code support for interfaces that implement interfaces
 - changes one implementation within tests to implement the interface implementer :)
 - removes some verbose tests to make the above changes more facile
 - do not call extendSchema after buildSchema as both now process extensions
 - use getIntrospectionQuery method instead of introspectionQuery object
 - type/lint changes
 - remove references to deprecated SchemaPrinter
  • Loading branch information
yaacovCR committed Feb 14, 2020
1 parent 561b880 commit bb02f68
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 239 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
language: node_js
node_js:
- "8"
- "10"
- '13'
- '12'
- '10'

install:
- npm config set spin=false
- npm install -g mocha coveralls
- npm install
- npm install graphql@$GRAPHQL_VERSION
- npm install @types/graphql@$TYPES_GRAPHQL_VERSION

script:
- npm test
Expand All @@ -19,4 +19,4 @@ script:
sudo: false

env:
- GRAPHQL_VERSION='^14.0' TYPES_GRAPHQL_VERSION='^14.0'
- GRAPHQL_VERSION='^15.0.0-rc.2'
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [9.0.0-graphql-15.0.0-rc.2.1.0](https://github.com/yaacovCR/graphql-tools-fork/compare/v8.5.4...v9.0.0-graphql-15.0.0-rc.2.1.0) (2020-02-14)

## [9.0.0-graphql-15.0.0-rc.2.0](https://github.com/yaacovCR/graphql-tools-fork/compare/v8.5.4...v9.0.0-graphql-15.0.0-rc.2.0) (2020-02-14)

## [9.0.0-graphql-15.0.0-rc.2.0](https://github.com/yaacovCR/graphql-tools-fork/compare/v8.5.4...v9.0.0-graphql-15.0.0-rc.2.0) (2020-02-14)

## [9.0.0-graphql-15.0.0-rc.2.0](https://github.com/yaacovCR/graphql-tools-fork/compare/v8.5.4...v9.0.0-graphql-15.0.0-rc.2.0) (2020-02-14)

## [9.0.0-graphql-15.0.0-rc.2.0](https://github.com/yaacovCR/graphql-tools-fork/compare/v8.5.4...v9.0.0-graphql-15.0.0-rc.2.0) (2020-02-14)

## [9.0.0-graphql-15.0.0-rc.2.0](https://github.com/yaacovCR/graphql-tools-fork/compare/v8.5.4...v9.0.0-graphql-15.0.0-rc.2.0) (2020-02-14)

### [8.5.4](https://github.com/yaacovCR/graphql-tools-fork/compare/v8.5.3...v8.5.4) (2020-02-13)

### [8.5.3](https://github.com/yaacovCR/graphql-tools-fork/compare/v8.5.2...v8.5.3) (2020-02-13)
Expand Down Expand Up @@ -90,6 +102,10 @@ All notable changes to this project will be documented in this file. See [standa

* **stitching:** custom scalars/enums ([fd1bd8f](https://github.com/yaacovCR/graphql-tools-fork/commit/fd1bd8fb55a357258e04d026bad661d39b316752))

### Features

* **graphql v15 support** See https://github.com/graphql/graphql-js/issues/2303.

## [8.2.0](https://github.com/yaacovCR/graphql-tools-fork/compare/v8.1.1...v8.2.0) (2020-01-06)


Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-tools-fork",
"version": "8.5.4",
"version": "9.0.0-graphql-15.0.0-rc.2.1.0",
"description": "Forked graphql-tools, still more useful tools to create and manipulate GraphQL schemas.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -56,7 +56,7 @@
"uuid": "^3.4.0"
},
"peerDependencies": {
"graphql": "^14.2.0"
"graphql": "^15.0.0-rc.2"
},
"devDependencies": {
"@types/apollo-upload-client": "^8.1.3",
Expand Down Expand Up @@ -84,7 +84,7 @@
"eslint-watch": "^6.0.1",
"express": "^4.17.1",
"express-graphql": "^0.9.0",
"graphql": "^14.5.8",
"graphql": "^15.0.0-rc.2",
"graphql-subscriptions": "^1.1.0",
"graphql-type-json": "^0.3.1",
"graphql-upload": "^9.0.0",
Expand Down
13 changes: 1 addition & 12 deletions src/generate/buildSchemaFromTypeDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
parse,
extendSchema,
buildASTSchema,
GraphQLSchema,
DocumentNode,
Expand All @@ -9,7 +8,6 @@ import {

import { ITypeDefinitions, GraphQLParseOptions } from '../Interfaces';

import extractExtensionDefinitions from './extractExtensionDefinitions';
import concatenateTypeDefs from './concatenateTypeDefs';
import SchemaError from './SchemaError';

Expand Down Expand Up @@ -40,16 +38,7 @@ function buildSchemaFromTypeDefinitions(
const backcompatOptions = { commentDescriptions: true };

// TODO fix types https://github.com/apollographql/graphql-tools/issues/542
let schema: GraphQLSchema = (buildASTSchema as any)(
astDocument,
backcompatOptions,
);

const extensionsAst = extractExtensionDefinitions(astDocument);
if (extensionsAst.definitions.length > 0) {
// TODO fix types https://github.com/apollographql/graphql-tools/issues/542
schema = (extendSchema as any)(schema, extensionsAst, backcompatOptions);
}
const schema: GraphQLSchema = buildASTSchema(astDocument, backcompatOptions);

return schema;
}
Expand Down
16 changes: 10 additions & 6 deletions src/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ function addMocksToSchema({
): any => {
// nullability doesn't matter for the purpose of mocking.
const fieldType = getNullableType(type);
const namedFieldType = getNamedType(fieldType);

if (fieldName && root && typeof root[fieldName] !== 'undefined') {
let result: any;
Expand All @@ -129,7 +128,11 @@ function addMocksToSchema({

// Now we merge the result with the default mock for this type.
// This allows overriding defaults while writing very little code.
if (mockFunctionMap.has(namedFieldType.name)) {
const namedFieldType: GraphQLNamedType = getNamedType(fieldType);
if (
namedFieldType != null &&
mockFunctionMap.has(namedFieldType.name)
) {
const mock = mockFunctionMap.get(namedFieldType.name);

result = mergeMocks(
Expand Down Expand Up @@ -200,7 +203,7 @@ function addMocksToSchema({
// if we get to here, we don't have a value, and we don't have a mock for this type,
// we could return undefined, but that would be hard to debug, so we throw instead.
// however, we returning it instead of throwing it, so preserveResolvers can handle the failures.
return Error(`No mock defined for type "${fieldType.name}"`);
return Error(`No mock defined for type "${fieldType.name as string}"`);
};
};

Expand Down Expand Up @@ -369,16 +372,17 @@ function getResolveType(namedFieldType: GraphQLNamedType) {

function assignResolveType(type: GraphQLType, preserveResolvers: boolean) {
const fieldType = getNullableType(type);
const namedFieldType = getNamedType(fieldType);
const namedFieldType: GraphQLNamedType = getNamedType(fieldType);

const oldResolveType = getResolveType(namedFieldType);
if (preserveResolvers && oldResolveType != null && oldResolveType.length) {
return;
}

if (
namedFieldType instanceof GraphQLUnionType ||
namedFieldType instanceof GraphQLInterfaceType
namedFieldType != null &&
(namedFieldType instanceof GraphQLUnionType ||
namedFieldType instanceof GraphQLInterfaceType)
) {
// the default `resolveType` always returns null. We add a fallback
// resolution that works with how unions and interface are mocked
Expand Down
4 changes: 2 additions & 2 deletions src/stitching/introspectSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApolloLink } from 'apollo-link';
import {
GraphQLSchema,
DocumentNode,
introspectionQuery,
getIntrospectionQuery,
buildClientSchema,
parse,
} from 'graphql';
Expand All @@ -12,7 +12,7 @@ import { Fetcher } from '../Interfaces';
import { combineErrors } from './errors';
import linkToFetcher from './linkToFetcher';

const parsedIntrospectionQuery: DocumentNode = parse(introspectionQuery);
const parsedIntrospectionQuery: DocumentNode = parse(getIntrospectionQuery());

export default function introspectSchema(
linkOrFetcher: ApolloLink | Fetcher,
Expand Down
2 changes: 0 additions & 2 deletions src/stitching/makeRemoteExecutableSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
BuildSchemaOptions,
DocumentNode,
} from 'graphql';
import { Options as PrintSchemaOptions } from 'graphql/utilities/schemaPrinter';

import { addResolversToSchema } from '../generate';
import { Fetcher, Operation } from '../Interfaces';
Expand Down Expand Up @@ -40,7 +39,6 @@ export default function makeRemoteExecutableSchema({
fetcher?: Fetcher;
createResolver?: (fetcher: Fetcher) => GraphQLFieldResolver<any, any>;
buildSchemaOptions?: BuildSchemaOptions;
printSchemaOptions?: PrintSchemaOptions;
}): GraphQLSchema {
let finalFetcher: Fetcher = fetcher;

Expand Down
8 changes: 8 additions & 0 deletions src/stitching/typeFromAST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ function makeInterfaceType(
return new GraphQLInterfaceType({
name: node.name.value,
fields: () => makeFields(node.fields),
interfaces: () =>
node.interfaces.map(
iface =>
createNamedStub(
iface.name.value,
'interface',
) as GraphQLInterfaceType,
),
description: getDescription(node, backcompatOptions),
resolveType: parent => resolveFromParentTypename(parent),
});
Expand Down
Loading

0 comments on commit bb02f68

Please sign in to comment.