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

Failing test: stitching fails when all selections on a field are delegated #5741

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/stitch/tests/__snapshots__/blah.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Blah creates expected schema 1`] = `
"type Query {
thingA(id: ID!): String
namespaceInB: NamespaceInB
}

type NamespaceInB {
dummy: ID!
thingA(id: ID!): String
}"
`;
116 changes: 116 additions & 0 deletions packages/stitch/tests/blah.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { graphql, OperationTypeNode, printSchema } from 'graphql/index';

Check failure on line 1 in packages/stitch/tests/blah.test.ts

View workflow job for this annotation

GitHub Actions / Type Check on GraphQL v15

'OperationTypeNode' is declared but its value is never read.
import { delegateToSchema } from '@graphql-tools/delegate';
import { makeExecutableSchema } from '@graphql-tools/schema';
import { stitchSchemas } from '@graphql-tools/stitch';

describe('Blah', () => {
const aResolvers = {
Query: {
thingA: async (_source: any, args: { id: string }) => {
return args.id;
},
},
};

const bResolvers = {
Query: {
namespaceInB: () => true,
},
};

const aggSchema = makeExecutableSchema({
typeDefs: /* GraphQL */ `
type Query {
thingA(id: ID!): String
}
`,
resolvers: aResolvers,
});

const bbfSchema = makeExecutableSchema({
typeDefs: /* GraphQL */ `
type Query {
namespaceInB: NamespaceInB
}

type NamespaceInB {
dummy: ID!
}
`,
resolvers: bResolvers,
});

const stitchedSchema = stitchSchemas({
subschemas: [{ schema: aggSchema }, { schema: bbfSchema }],
typeDefs: /* GraphQL */ `
extend type NamespaceInB {
thingA(id: ID!): String
}
`,
resolvers: {
NamespaceInB: {
thingA: {
resolve: async (_parent, args, context, info) => {
const result = await delegateToSchema({
schema: aggSchema,
operation: OperationTypeNode.QUERY,

Check failure on line 56 in packages/stitch/tests/blah.test.ts

View workflow job for this annotation

GitHub Actions / Type Check on GraphQL v15

'OperationTypeNode' only refers to a type, but is being used as a value here.
fieldName: 'thingA',
args,
context,
info,
});
return result;
},
},
},
},
});

it('creates expected schema', () => {
expect(printSchema(stitchedSchema)).toMatchSnapshot();
});

it('executes stitched query with dummy field', async () => {
const query = /* GraphQL */ `
query {
namespaceInB {
__typename
thingA(id: "abc")
}
}
`;

const result = await graphql({
schema: stitchedSchema,
source: query,
});
expect(result.errors).toBe(undefined);
expect(result.data).toEqual({
namespaceInB: {
__typename: 'NamespaceInB',
thingA: 'abc',
},
});
});

it('executes stitched query without dummy field', async () => {
const query = /* GraphQL */ `
query {
namespaceInB {
thingA(id: "abc")
}
}
`;

const result = await graphql({
schema: stitchedSchema,
source: query,
});
expect(result.errors).toBe(undefined);
expect(result.data).toEqual({
namespaceInB: {
thingA: 'abc',
},
});
});
});