-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow single, unnamed, queries
Allow single, unnamed, queries
- Loading branch information
Showing
5 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test/fixtures/graphql-tag/transpiles a single unnamed query/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import gql from 'graphql-tag'; | ||
|
||
const foo = gql`{foo}`; |
36 changes: 36 additions & 0 deletions
36
test/fixtures/graphql-tag/transpiles a single unnamed query/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const foo = { | ||
'kind': 'Document', | ||
'definitions': [{ | ||
'kind': 'OperationDefinition', | ||
'operation': 'query', | ||
'name': null, | ||
'variableDefinitions': null, | ||
'directives': [], | ||
'selectionSet': { | ||
'kind': 'SelectionSet', | ||
'selections': [{ | ||
'kind': 'Field', | ||
'alias': null, | ||
'name': { | ||
'kind': 'Name', | ||
'value': 'foo' | ||
}, | ||
'arguments': [], | ||
'directives': [], | ||
'selectionSet': null | ||
}] | ||
} | ||
}], | ||
'loc': { | ||
'start': 0, | ||
'end': 5, | ||
'source': { | ||
'body': '{foo}', | ||
'name': 'GraphQL request', | ||
'locationOffset': { | ||
'line': 1, | ||
'column': 1 | ||
} | ||
} | ||
} | ||
}; |
7 changes: 7 additions & 0 deletions
7
test/fixtures/graphql-tag/transpiles a single unnamed query/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"plugins": [ | ||
[ | ||
"../../../../src" | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { transform } from 'babel-core'; | ||
import assert from 'assert'; | ||
|
||
const fixture = "gql`type Widget { name: String } query {widget}`"; | ||
|
||
describe("When given an unnamed query", () => { | ||
let originalError; | ||
|
||
before(function() { | ||
originalError = console.error; | ||
}); | ||
|
||
after(function() { | ||
console.error = originalError; | ||
}); | ||
|
||
it('fails when there are other definitions', () => { | ||
const calls = []; | ||
|
||
console.error = (...args) => calls.push(args.join(' ')); | ||
|
||
transform(fixture, { | ||
plugins: [['./src']] | ||
}); | ||
|
||
assert.equal(calls.length, 1); | ||
assert.equal(calls[0], 'error Error: GraphQL query must have name.'); | ||
}); | ||
}); |