Skip to content

Commit

Permalink
fix: throw an error when query does not have name
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jun 26, 2017
1 parent 4f4d0eb commit 839547d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@ export default () => {
return head + quasi.value.raw;
}, '');

return parse(JSON.stringify([gql(source)])).program.body[0].expression.elements[0];
const queryDocument = gql(source);

for (const definition of queryDocument.definitions) {
if (!definition.name) {
// eslint-disable-next-line no-console
console.error('query', source);

throw new Error('GraphQL query must have name.');
}
}

return parse(JSON.stringify([queryDocument])).program.body[0].expression.elements[0];
};

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import gql from 'graphql-tag';

const foo = gql`query {foo}`;
const foo = gql`query foo {foo}`;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 839547d

Please sign in to comment.