-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #903 commit 0062abf Author: Lee Byron <[email protected]> Date: Fri Dec 1 12:49:38 2017 -0800 Amends this PR with a few additions: * Generalizes building a value from an AST, since "scalar" could be misleading, and supporting variable values within custom scalar literals can be valuable. * Replaces isNullish with isInvalid since `null` is a meaningful value as a result of literal parsing. * Exports this new utility from the top level commit 0ca6cf0 Merge: 37717b8 78e69d6 Author: Lee Byron <[email protected]> Date: Fri Dec 1 11:57:55 2017 -0800 Merge branch 'astValueToData' of https://github.com/APIs-guru/graphql-js into APIs-guru-astValueToData commit 78e69d6 Author: Ivan Goncharov <[email protected]> Date: Sun Jun 11 01:07:47 2017 +0300 Fix 'serialize' stub used in buildASTSchema commit a0688c6 Author: Ivan Goncharov <[email protected]> Date: Fri Jun 9 23:24:55 2017 +0300 Provide reasonable default version of 'parseLiteral' commit 313d66e Author: Ivan Goncharov <[email protected]> Date: Fri Jun 9 23:22:49 2017 +0300 Add test for building client schema with default value on custom scalar
- Loading branch information
Showing
14 changed files
with
220 additions
and
48 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
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
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
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
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
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
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,73 @@ | ||
/** | ||
* Copyright (c) 2017, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
import { describe, it } from 'mocha'; | ||
import { expect } from 'chai'; | ||
import { valueFromASTUntyped } from '../valueFromASTUntyped'; | ||
import { parseValue } from '../../language'; | ||
|
||
describe('valueFromASTUntyped', () => { | ||
|
||
function testCase(valueText, expected) { | ||
expect( | ||
valueFromASTUntyped(parseValue(valueText)) | ||
).to.deep.equal(expected); | ||
} | ||
|
||
function testCaseWithVars(valueText, variables, expected) { | ||
expect( | ||
valueFromASTUntyped(parseValue(valueText), variables) | ||
).to.deep.equal(expected); | ||
} | ||
|
||
it('parses simple values', () => { | ||
testCase('null', null); | ||
testCase('true', true); | ||
testCase('false', false); | ||
testCase('123', 123); | ||
testCase('123.456', 123.456); | ||
testCase('"abc123"', 'abc123'); | ||
}); | ||
|
||
it('parses lists of values', () => { | ||
testCase('[true, false]', [ true, false ]); | ||
testCase('[true, 123.45]', [ true, 123.45 ]); | ||
testCase('[true, null]', [ true, null ]); | ||
testCase('[true, ["foo", 1.2]]', [ true, [ 'foo', 1.2 ] ]); | ||
}); | ||
|
||
it('parses input objects', () => { | ||
testCase( | ||
'{ int: 123, bool: false }', | ||
{ int: 123, bool: false } | ||
); | ||
testCase( | ||
'{ foo: [ { bar: "baz"} ] }', | ||
{ foo: [ { bar: 'baz'} ] } | ||
); | ||
}); | ||
|
||
it('parses enum values as plain strings', () => { | ||
testCase('TEST_ENUM_VALUE', 'TEST_ENUM_VALUE'); | ||
testCase('[TEST_ENUM_VALUE]', [ 'TEST_ENUM_VALUE' ]); | ||
}); | ||
|
||
it('parses variables', () => { | ||
testCaseWithVars('$testVariable', { testVariable: 'foo' }, 'foo'); | ||
testCaseWithVars('[$testVariable]', { testVariable: 'foo' }, [ 'foo' ]); | ||
testCaseWithVars( | ||
'{a:[$testVariable]}', | ||
{ testVariable: 'foo' }, | ||
{ a: [ 'foo' ] } | ||
); | ||
testCaseWithVars('$testVariable', { testVariable: null }, null); | ||
testCaseWithVars('$testVariable', {}, undefined); | ||
}); | ||
|
||
}); |
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
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
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
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
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
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
Oops, something went wrong.