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

Commit

Permalink
fix(stitching): include specified directives even when merging of dir…
Browse files Browse the repository at this point in the history
…ectives is disabled
  • Loading branch information
yaacovCR committed Sep 22, 2019
1 parent f486a6d commit 0a25e9b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/stitching/mergeSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ export default function mergeSchemas({
mutation: types.Mutation as GraphQLObjectType,
subscription: types.Subscription as GraphQLObjectType,
types: Object.keys(types).map(key => types[key]),
directives: directives.map((directive) => recreateDirective(directive, resolveType))
directives: directives.length ?
directives.map((directive) => recreateDirective(directive, resolveType)) :
undefined
});

extensions.forEach(extension => {
Expand Down
53 changes: 53 additions & 0 deletions src/test/testAlternateMergeSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import { forAwaitEach } from 'iterall';
import { createResolveType, fieldToFieldConfig } from '../stitching/schemaRecreation';
import { makeExecutableSchema } from '../makeExecutableSchema';
import { delegateToSchema } from '../stitching';

let linkSchema = `
"""
Expand Down Expand Up @@ -645,6 +646,58 @@ describe('mergeSchemas', () => {

expect(response.data.getTestScalar).to.equal('test');
});

it('can use @include directives', async () => {
const schema = makeExecutableSchema({
typeDefs: `
type WrappingType {
subfield: String
}
type Query {
get1: WrappingType
}
`,
resolvers: {
Query: {
get1: () => ({ subfield: 'test'})
}
}
});
const mergedSchema = mergeSchemas({
schemas: [
schema,
`
type Query {
get2: WrappingType
}
`
],
resolvers: {
Query: {
get2: (root, args, context, info) => {
return delegateToSchema({
schema: schema,
operation: 'query',
fieldName: 'get1',
context,
info
})
}
}
}
});

const query = `
{
get2 @include(if: true) {
subfield
}
}
`;
const response = await graphql(mergedSchema, query);
console.log(JSON.stringify(response, null, 2));
expect(response.data.get2.subfield).to.equal('test');
});
});

describe('onTypeConflict', () => {
Expand Down

0 comments on commit 0a25e9b

Please sign in to comment.