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

Fix type declaration for SchemaVisitor #1030

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,9 @@

### vNext

* Fix `SchemaVisitor` type declaration to allow null and undefined return values <br />
[@rexxars](https://github.com/rexxars) in
[#1030](https://github.com/apollographql/graphql-tools/pull/1030)
* Make `WrapQuery` work for non-root fields <br />
[@mdlavin](https://github.com/mdlavin) in
[#1007](https://github.com/apollographql/graphql-tools/pull/1008)
Expand Down
8 changes: 4 additions & 4 deletions src/transforms/visitSchema.ts
Expand Up @@ -28,12 +28,12 @@ export enum VisitSchemaKind {
MUTATION = 'VisitSchemaKind.MUTATION',
SUBSCRIPTION = 'VisitSchemaKind.SUBSCRIPTION',
}
// I couldn't make keys to be forced to be enum values
export type SchemaVisitor = { [key: string]: TypeVisitor };

export type SchemaVisitor = { [key in VisitSchemaKind]?: TypeVisitor };
export type TypeVisitor = (
type: GraphQLType,
schema: GraphQLSchema,
) => GraphQLNamedType;
) => GraphQLNamedType | null | undefined;

export function visitSchema(
schema: GraphQLSchema,
Expand All @@ -57,7 +57,7 @@ export function visitSchema(
const specifiers = getTypeSpecifiers(type, schema);
const typeVisitor = getVisitor(visitor, specifiers);
if (typeVisitor) {
const result: GraphQLNamedType | null | undefined = typeVisitor(
const result = typeVisitor(
type,
schema,
);
Expand Down