Skip to content

Commit

Permalink
Use Kind.DIRECTIVE_DEFINITION constant rather than string literal.
Browse files Browse the repository at this point in the history
This is just for stability.  I know we don't do it everywhere right now, but
we should!

This also removes the extra function, but I don't think we're really
getting too much from that now, or later.  The constant comparison should be
the ideal way of doing this, and TypeScript should be able to do the type
narrowing on its own.
  • Loading branch information
abernix committed May 22, 2019
1 parent 83e49cb commit ab282e2
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions packages/apollo-server-core/src/utils/isDirectiveDefined.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import {
DocumentNode,
DefinitionNode,
DirectiveDefinitionNode,
Kind,
} from 'graphql/language';

const isDirectiveNode = (
node: DefinitionNode,
): node is DirectiveDefinitionNode => node.kind === 'DirectiveDefinition';

export const isDirectiveDefined = (
typeDefs: DocumentNode[],
directiveName: string,
) =>
typeDefs.some(typeDef =>
typeDef.definitions.some(
definition =>
isDirectiveNode(definition) && definition.name.value === directiveName,
definition.kind === Kind.DIRECTIVE_DEFINITION &&
definition.name.value === directiveName,
),
);

0 comments on commit ab282e2

Please sign in to comment.