Skip to content
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- `apollo-env`
- <First `apollo-env` related entry goes here>
- `apollo-graphql`
- <First `apollo-graphql` related entry goes here>
- Complex directive arguments don't break `transformSchema` (Fixes #2162)
- `apollo-language-server`
- <First `apollo-language-server` related entry goes here>
- `apollo-tools`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { buildSchema, printSchema } from "graphql";
import { transformSchema } from "../transformSchema";

describe("transformSchema", () => {
test("no-op transform leaves types untouched", () => {
const schema = buildSchema(`#graphql
type Query {
foo: String @test(baz: { bar: "hello" })
}

input DirectiveArg {
bar: String
}

# https://github.com/apollographql/apollo-tooling/issues/2162
directive @test(baz: DirectiveArg) on FIELD_DEFINITION
`);

const newSchema = transformSchema(schema, namedType => namedType);

expect(printSchema(newSchema)).toEqual(printSchema(schema));
});
});
16 changes: 14 additions & 2 deletions packages/apollo-graphql/src/schema/transformSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
GraphQLUnionType,
isInputObjectType,
GraphQLInputObjectType,
GraphQLInputFieldConfigMap
GraphQLInputFieldConfigMap,
GraphQLDirective
} from "graphql";
import { mapValues } from "../utilities/mapValues";

Expand Down Expand Up @@ -53,7 +54,8 @@ export function transformSchema(
types: Object.values(typeMap),
query: replaceMaybeType(schemaConfig.query),
mutation: replaceMaybeType(schemaConfig.mutation),
subscription: replaceMaybeType(schemaConfig.subscription)
subscription: replaceMaybeType(schemaConfig.subscription),
directives: replaceDirectives(schemaConfig.directives)
});

function recreateNamedType(type: GraphQLNamedType): GraphQLNamedType {
Expand Down Expand Up @@ -145,4 +147,14 @@ export function transformSchema(
type: replaceType(arg.type)
}));
}

function replaceDirectives(directives: GraphQLDirective[]) {
return directives.map(directive => {
const config = directive.toConfig();
return new GraphQLDirective({
...config,
args: replaceArgs(config.args)
});
});
}
}