Skip to content

Commit

Permalink
Merge f9a5ff1 into 2394f0c
Browse files Browse the repository at this point in the history
  • Loading branch information
Evans Hauser committed Jan 11, 2019
2 parents 2394f0c + f9a5ff1 commit 28a54bf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -16,7 +16,9 @@
* Fix default merged resolver behavior <br/>
[@mfix22](https://github.com/mfix22) in [#983](https://github.com/apollographql/graphql-tools/pull/983)
* Use `TArgs` generic wherever `IFieldResolver` is used. <br/>
[@brikou](https://github.com/brikou) in [#955](https://github.com/apollographql/graphql-tools/pull/955)
[@brikou](https://github.com/brikou) in [#955](https://github.com/apollographql/graphql-tools/pull/955)
* Include deprecations from string SDL in mergeSchemas. <br/>
[@evans](https://github.com/evans) in [#1041](https://github.com/apollographql/graphql-tools/pull/1041)

### 4.0.3

Expand Down
30 changes: 25 additions & 5 deletions src/stitching/typeFromAST.ts
Expand Up @@ -23,7 +23,9 @@ import {
UnionTypeDefinitionNode,
valueFromAST,
getDescription,
GraphQLString
GraphQLString,
GraphQLFieldConfig,
StringValueNode,
} from 'graphql';
import resolveFromParentType from './resolveFromParentTypename';

Expand Down Expand Up @@ -139,13 +141,31 @@ function makeInputObjectType(
});
}

function makeFields(nodes: ReadonlyArray<FieldDefinitionNode>) {
const result = {};
nodes.forEach(node => {
function makeFields(
nodes: ReadonlyArray<FieldDefinitionNode>,
): Record<string, GraphQLFieldConfig<any, any>> {
const result: Record<string, GraphQLFieldConfig<any, any>> = {};
nodes.forEach((node) => {
const deprecatedDirective = node.directives.find(
(directive) =>
directive && directive.name && directive.name.value === 'deprecated',
);
const deprecatedArgument =
deprecatedDirective &&
deprecatedDirective.arguments &&
deprecatedDirective.arguments.find(
(arg) => arg && arg.name && arg.name.value === 'reason',
);
const deprecationReason =
deprecatedArgument &&
deprecatedArgument.value &&
(deprecatedArgument.value as StringValueNode).value;

result[node.name.value] = {
type: resolveType(node.type, 'object'),
type: resolveType(node.type, 'object') as GraphQLObjectType,
args: makeValues(node.arguments),
description: getDescription(node, backcompatOptions),
deprecationReason,
};
});
return result;
Expand Down
38 changes: 37 additions & 1 deletion src/test/testMergeSchemas.ts
Expand Up @@ -9,6 +9,7 @@ import {
subscribe,
parse,
ExecutionResult,
findDeprecatedUsages,
} from 'graphql';
import mergeSchemas from '../stitching/mergeSchemas';
import {
Expand Down Expand Up @@ -2685,7 +2686,7 @@ fragment BookingFragment on Booking {
};

schema = mergeSchemas({
schemas: [ schema ],
schemas: [schema],
resolvers
});

Expand All @@ -2697,5 +2698,40 @@ fragment BookingFragment on Booking {
expect(result.data.book.cat).to.equal('Test');
});
});

describe('deprecation', () => {
it('should retain deprecation information', async () => {
const typeDefs = `
type Query {
book: Book
}
type Book {
category: String! @deprecated(reason: "yolo")
}
`;

const query = `query {
book {
category
}
}`;

const resolvers = {
Query: {
book: () => ({ category: 'Test' })
}
};

const schema = mergeSchemas({
schemas: [propertySchema, typeDefs],
resolvers
});

const deprecatedUsages = findDeprecatedUsages(schema, parse(query));
expect(deprecatedUsages).not.empty;
expect(deprecatedUsages.length).to.equal(1);
expect(deprecatedUsages.find(error => Boolean(error && error.message.match(/deprecated/) && error.message.match(/yolo/))));
});
});
});
});

0 comments on commit 28a54bf

Please sign in to comment.