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

Update dev graphql to 16 and add in peerDependency #1345

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composition-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"@apollo/query-graphs": "file:../query-graphs-js"
},
"peerDependencies": {
"graphql": "^15.7.0"
"graphql": "^15.7.0 || ^16.1.0"
}
}
10 changes: 4 additions & 6 deletions composition-js/src/__tests__/validation_errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ describe('composition', () => {
type A @key(fields: "id") {
id: ID! @external
x: Int @external
y: Int @requires(fields: "x")
z: Int @requires(fields: "x")
y: Int @requires(fields: "x")
z: Int @requires(fields: "x")
}
`
};
Expand All @@ -43,8 +43,7 @@ describe('composition', () => {
a {
y
}
}
cannot be satisfied by the subgraphs because:
}cannot be satisfied by the subgraphs because:
- from subgraph "A": cannot find field "A.y".
- from subgraph "B": cannot satisfy @require conditions on field "A.y" (please ensure that this is not due to key field "id" being accidentally marked @external).
`,
Expand All @@ -54,8 +53,7 @@ describe('composition', () => {
a {
z
}
}
cannot be satisfied by the subgraphs because:
}cannot be satisfied by the subgraphs because:
- from subgraph "A": cannot find field "A.z".
- from subgraph "B": cannot satisfy @require conditions on field "A.z" (please ensure that this is not due to key field "id" being accidentally marked @external).
`
Expand Down
17 changes: 8 additions & 9 deletions composition-js/src/merging/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
isFederationType,
Directive,
isFederationField,
SchemaRootKind,
CompositeType,
Subgraphs,
federationBuiltIns,
Expand All @@ -54,7 +53,7 @@ import {
isInterfaceType,
sourceASTs,
} from "@apollo/federation-internals";
import { ASTNode, GraphQLError, DirectiveLocationEnum } from "graphql";
import { ASTNode, GraphQLError, DirectiveLocation, OperationTypeNode } from "graphql";
import {
CompositionHint,
HintID,
Expand Down Expand Up @@ -209,7 +208,7 @@ function isMergedDirective(definition: DirectiveDefinition | Directive): boolean
// This mainly avoid us trying to set the supergraph root in the rare case where the supergraph has
// no actual queries (knowing that subgraphs will _always_ have a queries since they have at least
// the federation ones).
function filteredRoot(def: SchemaDefinition, rootKind: SchemaRootKind): ObjectType | undefined {
function filteredRoot(def: SchemaDefinition, rootKind: OperationTypeNode): ObjectType | undefined {
const type = def.root(rootKind)?.type;
return type && hasMergedFields(type) ? type : undefined;
}
Expand Down Expand Up @@ -249,7 +248,7 @@ function hasTagUsage(subgraph: Schema): boolean {
return !!directive && directive.applications().length > 0;
}

function locationString(locations: DirectiveLocationEnum[]): string {
function locationString(locations: DirectiveLocation[]): string {
if (locations.length === 0) {
return "";
}
Expand Down Expand Up @@ -339,7 +338,7 @@ class Merger {
}
}

if (!this.merged.schemaDefinition.rootType('query')) {
if (!this.merged.schemaDefinition.rootType(OperationTypeNode.QUERY)) {
this.errors.push(new GraphQLError("No queries found in any subgraph: a supergraph must have a query root type."));
}

Expand Down Expand Up @@ -1329,7 +1328,7 @@ class Merger {

let repeatable: boolean | undefined = undefined;
let inconsistentRepeatable = false;
let locations: DirectiveLocationEnum[] | undefined = undefined;
let locations: DirectiveLocation[] | undefined = undefined;
let inconsistentLocations = false;
for (const source of sources) {
if (!source) {
Expand Down Expand Up @@ -1388,7 +1387,7 @@ class Merger {
private mergeExecutionDirectiveDefinition(sources: (DirectiveDefinition | undefined)[], dest: DirectiveDefinition) {
let repeatable: boolean | undefined = undefined;
let inconsistentRepeatable = false;
let locations: DirectiveLocationEnum[] | undefined = undefined;
let locations: DirectiveLocation[] | undefined = undefined;
let inconsistentLocations = false;
for (const source of sources) {
if (!source) {
Expand Down Expand Up @@ -1483,12 +1482,12 @@ class Merger {
}
}

private extractLocations(source: DirectiveDefinition): DirectiveLocationEnum[] {
private extractLocations(source: DirectiveDefinition): DirectiveLocation[] {
// We sort the locations so that the return list of locations essentially act like a set.
return this.filterExecutableDirectiveLocations(source).concat().sort();
}

private filterExecutableDirectiveLocations(source: DirectiveDefinition): readonly DirectiveLocationEnum[] {
private filterExecutableDirectiveLocations(source: DirectiveDefinition): readonly DirectiveLocation[] {
if (MERGED_TYPE_SYSTEM_DIRECTIVES.includes(source.name)) {
return source.locations;
}
Expand Down
7 changes: 3 additions & 4 deletions composition-js/src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
Operation,
operationToDocument,
Schema,
SchemaRootKind,
Selection,
selectionOfElement,
SelectionSet,
Expand Down Expand Up @@ -48,7 +47,7 @@ import {
SimultaneousPathsWithLazyIndirectPaths,
advanceOptionsToString,
} from "@apollo/query-graphs";
import { print } from "graphql";
import { OperationTypeNode, print } from "graphql";

const debug = newDebugLogger('validation');

Expand Down Expand Up @@ -247,7 +246,7 @@ export function computeSubgraphPaths(supergraphPath: RootPath<Transition>, subgr
}
}

function initialSubgraphPaths(kind: SchemaRootKind, subgraphs: QueryGraph): RootPath<Transition>[] {
function initialSubgraphPaths(kind: OperationTypeNode, subgraphs: QueryGraph): RootPath<Transition>[] {
const root = subgraphs.root(kind);
assert(root, () => `The supergraph shouldn't have a ${kind} root if no subgraphs have one`);
assert(
Expand All @@ -266,7 +265,7 @@ export class ValidationState {
) {
}

static initial(supergraph: QueryGraph, kind: SchemaRootKind, subgraphs: QueryGraph) {
static initial(supergraph: QueryGraph, kind: OperationTypeNode, subgraphs: QueryGraph) {
return new ValidationState(GraphPath.fromGraphRoot(supergraph, kind)!, initialSubgraphPaths(kind, subgraphs));
}

Expand Down
4 changes: 2 additions & 2 deletions gateway-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"access": "public"
},
"dependencies": {
"@apollo/client": "^3.5.6",
"@apollo/composition": "file:../composition-js",
"@apollo/core-schema": "^0.2.0",
"@apollo/query-planner": "file:../query-planner-js",
Expand All @@ -37,12 +38,11 @@
"apollo-server-env": "^3.0.0 || ^4.0.0",
"apollo-server-errors": "^2.5.0 || ^3.0.0",
"apollo-server-types": "^0.9.0 || ^3.0.0",
"apollo-utilities": "^1.3.0",
"loglevel": "^1.6.1",
"make-fetch-happen": "^8.0.0",
"pretty-format": "^27.0.0"
},
"peerDependencies": {
"graphql": "^15.7.0"
"graphql": "^15.7.0 || ^16.1.0"
}
}
2 changes: 1 addition & 1 deletion gateway-js/src/__tests__/execution-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@apollo/gateway';
import { QueryPlan, QueryPlanner } from '@apollo/query-planner';
import { LocalGraphQLDataSource } from '../datasources/LocalGraphQLDataSource';
import { mergeDeep } from 'apollo-utilities';
import { mergeDeep } from '@apollo/client/utilities';

import { queryPlanSerializer, astSerializer } from 'apollo-federation-integration-testsuite';
import gql from 'graphql-tag';
Expand Down
2 changes: 1 addition & 1 deletion gateway-js/src/datasources/LocalGraphQLDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class LocalGraphQLDataSource<
throw new Error(result.errors.map((error) => error.message).join('\n\n'));
}

const sdl = result.data && result.data._service && result.data._service.sdl;
const sdl = result.data && result.data._service && (result.data._service as any).sdl;
return parse(sdl);
}
}
3 changes: 2 additions & 1 deletion gateway-js/src/executeQueryPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
GraphQLFormattedError,
isAbstractType,
GraphQLSchema,
isTypeSubTypeOf
} from 'graphql';
import { Trace, google } from 'apollo-reporting-protobuf';
import { GraphQLDataSource, GraphQLDataSourceRequestKind } from './datasources/types';
Expand Down Expand Up @@ -546,7 +547,7 @@ function doesTypeConditionMatch(
}

if (isAbstractType(conditionalType)) {
return schema.isSubType(conditionalType, type);
return isTypeSubTypeOf(schema, type, conditionalType)
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ describe('cleanErrorOfInaccessibleNames', () => {
const schema = coreSchema.toAPISchema().toGraphQLJSSchema();

it('removes inaccessible type names from error messages', async () => {
const result = await execute(schema, parse('{fooField{someField}}'), {
fooField: {
__typename: 'Bar',
someField: 'test',
},
const result = await execute({
schema, document: parse('{fooField{someField}}'), rootValue:{
fooField: {
__typename: 'Bar',
someField: 'test',
},
}
});

const cleaned = cleanErrorOfInaccessibleNames(schema, result.errors![0]!);
expect(cleaned.message).toMatchInlineSnapshot(
`"Abstract type \\"Foo\\" was resolve to a type [inaccessible type] that does not exist inside schema."`,
`"Abstract type \\"Foo\\" was resolved to a type [inaccessible type] that does not exist inside the schema."`,
);
});

Expand Down
2 changes: 1 addition & 1 deletion harmonizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"whatwg-url": "^11.0.0"
},
"peerDependencies": {
"graphql": "^15.7.0"
"graphql": "^15.7.0 || ^16.1.0"
}
}
2 changes: 1 addition & 1 deletion internals-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"access": "public"
},
"peerDependencies": {
"graphql": "^15.7.0"
"graphql": "^15.7.0 || ^16.1.0"
},
"devDependencies": {
"@types/js-levenshtein": "1.1.1"
Expand Down
9 changes: 5 additions & 4 deletions internals-js/src/__tests__/definitions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
BuiltIns
} from '../../dist/definitions';
import {
OperationTypeNode,
printSchema as printGraphQLjsSchema
} from 'graphql';
import { defaultPrintOptions, printSchema } from '../../dist/print';
Expand Down Expand Up @@ -114,15 +115,15 @@ expect.extend({

test('building a simple schema programatically', () => {
const schema = new Schema(federationBuiltIns);
const queryType = schema.schemaDefinition.setRoot('query', schema.addType(new ObjectType('Query'))).type;
const queryType = schema.schemaDefinition.setRoot(OperationTypeNode.QUERY, schema.addType(new ObjectType('Query'))).type;
const typeA = schema.addType(new ObjectType('A'));
const key = federationBuiltIns.keyDirective(schema);

queryType.addField('a', typeA);
typeA.addField('q', queryType);
typeA.applyDirective(key, { fields: 'a'});

expect(queryType).toBe(schema.schemaDefinition.root('query')!.type);
expect(queryType).toBe(schema.schemaDefinition.root(OperationTypeNode.QUERY)!.type);
expect(queryType).toHaveField('a', typeA);
expect(typeA).toHaveField('q', queryType);
expect(typeA).toHaveDirective(key, { fields: 'a'});
Expand Down Expand Up @@ -153,7 +154,7 @@ test('parse schema and modify', () => {
const inaccessibleDirective = schema.directive('inaccessible')!;
expectObjectType(queryType);
expectObjectType(typeA);
expect(schema.schemaDefinition.root('query')!.type).toBe(queryType);
expect(schema.schemaDefinition.root(OperationTypeNode.QUERY)!.type).toBe(queryType);
expect(queryType).toHaveField('a', typeA);
const f2 = typeA.field('f2');
expect(f2).toHaveDirective(inaccessibleDirective);
Expand Down Expand Up @@ -561,7 +562,7 @@ test('default arguments for directives', () => {
const schema = parseSchema(sdl);
expect(printSchema(schema)).toMatchString(sdl);

const query = schema.schemaDefinition.root('query')!.type;
const query = schema.schemaDefinition.root(OperationTypeNode.QUERY)!.type;
const exampleDirective = schema.directive('Example')!;
expect(query).toHaveField('v1');
expect(query).toHaveField('v2');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ObjectType } from '../definitions';
import { buildSchema } from '../buildSchema';
import { removeInaccessibleElements } from '../inaccessibleSpec';
import { OperationTypeNode } from 'graphql';

describe('removeInaccessibleElements', () => {
it(`removes @inaccessible fields`, () => {
Expand Down Expand Up @@ -29,7 +30,7 @@ describe('removeInaccessibleElements', () => {

removeInaccessibleElements(schema);

const queryType = schema.schemaDefinition.rootType('query')!;
const queryType = schema.schemaDefinition.rootType(OperationTypeNode.QUERY)!;

expect(queryType.field('someField')).toBeDefined();
expect(queryType.field('privateField')).toBeUndefined();
Expand Down Expand Up @@ -214,7 +215,7 @@ describe('removeInaccessibleElements', () => {

removeInaccessibleElements(schema);

expect(schema.schemaDefinition.rootType('query')).toBeUndefined();
expect(schema.schemaDefinition.rootType(OperationTypeNode.QUERY)).toBeUndefined();
expect(schema.type('Query')).toBeUndefined();

expect(() => schema.validate()).toThrow();
Expand Down Expand Up @@ -254,7 +255,7 @@ describe('removeInaccessibleElements', () => {

removeInaccessibleElements(schema);

expect(schema.schemaDefinition.rootType('mutation')).toBeUndefined();
expect(schema.schemaDefinition.rootType(OperationTypeNode.MUTATION)).toBeUndefined();
expect(schema.type('Mutation')).toBeUndefined();
});

Expand Down Expand Up @@ -292,7 +293,7 @@ describe('removeInaccessibleElements', () => {

removeInaccessibleElements(schema);

expect(schema.schemaDefinition.rootType('subscription')).toBeUndefined();
expect(schema.schemaDefinition.rootType(OperationTypeNode.SUBSCRIPTION)).toBeUndefined();
expect(schema.type('Subscription')).toBeUndefined();
});
});
11 changes: 6 additions & 5 deletions internals-js/src/buildSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
DefinitionNode,
DirectiveDefinitionNode,
DirectiveLocationEnum,
DirectiveNode,
DocumentNode,
FieldDefinitionNode,
Expand All @@ -18,7 +17,9 @@ import {
StringValueNode,
ASTNode,
SchemaExtensionNode,
parseType
parseType,
Kind,
DirectiveLocation
} from "graphql";
import { Maybe } from "graphql/jsutils/Maybe";
import {
Expand Down Expand Up @@ -332,9 +333,9 @@ export function builtTypeReference(encodedType: string, schema: Schema): Type {

function buildTypeReferenceFromAST(typeNode: TypeNode, schema: Schema): Type {
switch (typeNode.kind) {
case 'ListType':
case Kind.LIST_TYPE:
return new ListType(buildTypeReferenceFromAST(typeNode.type, schema));
case 'NonNullType':
case Kind.NON_NULL_TYPE:
const wrapped = buildTypeReferenceFromAST(typeNode.type, schema);
if (wrapped.kind == 'NonNullType') {
throw new GraphQLError(`Cannot apply the non-null operator (!) twice to the same type`, typeNode);
Expand Down Expand Up @@ -368,7 +369,7 @@ function buildDirectiveDefinitionInner(directiveNode: DirectiveDefinitionNode, d
buildArgumentDefinitionInner(inputValueDef, directive.addArgument(inputValueDef.name.value));
}
directive.repeatable = directiveNode.repeatable;
const locations = directiveNode.locations.map(({ value }) => value as DirectiveLocationEnum);
const locations = directiveNode.locations.map(({ value }) => value as DirectiveLocation);
directive.addLocations(...locations);
directive.description = directiveNode.description?.value;
directive.sourceAST = directiveNode;
Expand Down
Loading