Skip to content

Commit

Permalink
changes the way the parser filters the array of definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
rasulomaroff authored and brainkim committed Apr 27, 2022
1 parent 9eb93c7 commit 50c3c81
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/react/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,31 @@ export function parser(document: DocumentNode): IDocumentDefinition {
`to convert your operation into a document`
);

const fragments = document.definitions.filter(
(x: DefinitionNode) => x.kind === 'FragmentDefinition'
);

const queries = document.definitions.filter(
(x: DefinitionNode) =>
x.kind === 'OperationDefinition' && x.operation === 'query'
);

const mutations = document.definitions.filter(
(x: DefinitionNode) =>
x.kind === 'OperationDefinition' && x.operation === 'mutation'
);

const subscriptions = document.definitions.filter(
(x: DefinitionNode) =>
x.kind === 'OperationDefinition' && x.operation === 'subscription'
);
const fragments: DefinitionNode[] = []
const queries: DefinitionNode[] = []
const mutations: DefinitionNode[] = []
const subscriptions: DefinitionNode[] = []

for (const x of document.definitions) {
if (x.kind === 'FragmentDefinition') {
fragments.push(x);
continue
}

if (x.kind === 'OperationDefinition') {
switch (x.operation) {
case 'query':
queries.push(x);
break;
case 'mutation':
mutations.push(x);
break;
case 'subscription':
subscriptions.push(x);
break;
}
}
}

invariant(
!fragments.length ||
Expand Down

0 comments on commit 50c3c81

Please sign in to comment.