Skip to content

Commit

Permalink
fix: type directives are now parsed on TypeComposers initialization
Browse files Browse the repository at this point in the history
closes #273
  • Loading branch information
nodkz committed Aug 2, 2020
1 parent 05b4ede commit e98715a
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/EnumTypeComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ export class EnumTypeComposer<TContext> {

this._gqcFields = convertEnumValuesToConfig(this._gqType.getValues(), this.schemaComposer);

if (graphqlType?.astNode?.directives) {
this.setExtension(
'directives',
this.schemaComposer.typeMapper.parseDirectives(graphqlType?.astNode?.directives)
);
}

// alive proper Flow type casting in autosuggestions for class with Generics
/* :: return this; */
}
Expand Down
7 changes: 7 additions & 0 deletions src/InputTypeComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ export class InputTypeComposer<TContext> {
);
}

if (graphqlType?.astNode?.directives) {
this.setExtension(
'directives',
this.schemaComposer.typeMapper.parseDirectives(graphqlType?.astNode?.directives)
);
}

// alive proper Flow type casting in autosuggestions for class with Generics
/* :: return this; */
}
Expand Down
7 changes: 7 additions & 0 deletions src/InterfaceTypeComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ export class InterfaceTypeComposer<TSource, TContext> {
);
}

if (graphqlType?.astNode?.directives) {
this.setExtension(
'directives',
this.schemaComposer.typeMapper.parseDirectives(graphqlType?.astNode?.directives)
);
}

// alive proper Flow type casting in autosuggestions for class with Generics
/* :: return this; */
}
Expand Down
7 changes: 7 additions & 0 deletions src/ObjectTypeComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,13 @@ export class ObjectTypeComposer<TSource, TContext> {
);
}

if (graphqlType?.astNode?.directives) {
this.setExtension(
'directives',
this.schemaComposer.typeMapper.parseDirectives(graphqlType?.astNode?.directives)
);
}

// alive proper Flow type casting in autosuggestions for class with Generics
/* :: return this; */
}
Expand Down
7 changes: 7 additions & 0 deletions src/ScalarTypeComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ export class ScalarTypeComposer<TContext> {
this.setParseValue(parseValue);
this.setParseLiteral(parseLiteral);

if (graphqlType?.astNode?.directives) {
this.setExtension(
'directives',
this.schemaComposer.typeMapper.parseDirectives(graphqlType?.astNode?.directives)
);
}

// alive proper Flow type casting in autosuggestions for class with Generics
/* :: return this; */
}
Expand Down
7 changes: 7 additions & 0 deletions src/UnionTypeComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ export class UnionTypeComposer<TSource, TContext> {
this._gqcTypeResolvers = new Map();
}

if (graphqlType?.astNode?.directives) {
this.setExtension(
'directives',
this.schemaComposer.typeMapper.parseDirectives(graphqlType?.astNode?.directives)
);
}

// alive proper Flow type casting in autosuggestions for class with Generics
/* :: return this; */
}
Expand Down
60 changes: 60 additions & 0 deletions src/__tests__/github_issues/273-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* @flow */

import { buildSchema } from 'graphql';
import { SchemaComposer, dedent } from '../..';

describe('github issue #273: Object directives are removed from schema', () => {
it('should keep @test directive on TestObject', () => {
const schema = buildSchema(`
directive @test on OBJECT | INPUT_OBJECT | SCALAR | ENUM
type ModifyMe @test {
id: ID!
}
input Input @test {
id: ID!
}
scalar Scalar @test
enum Enum @test
type Query {
hello(a: Input, s: Scalar, e: Enum): ModifyMe
}
`);

const sc = new SchemaComposer(schema);

const sdl = sc.toSDL({
exclude: ['ID', 'String', 'Int', 'Boolean', 'Float'],
});

expect(sdl).toBe(dedent`
directive @test on OBJECT | INPUT_OBJECT | SCALAR | ENUM
"""Exposes a URL that specifies the behaviour of this scalar."""
directive @specifiedBy(
"""The URL that specifies the behaviour of this scalar."""
url: String!
) on SCALAR
enum Enum @test
input Input @test {
id: ID!
}
type ModifyMe @test {
id: ID!
}
type Query {
hello(a: Input, s: Scalar, e: Enum): ModifyMe
}
scalar Scalar @test
`);
});
});

0 comments on commit e98715a

Please sign in to comment.