-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: switch own JSON type implementation on improved `graphql-type-j…
…son` package, due its popularity and last [amazing changes](taion/graphql-type-json#31) by @benjie
- Loading branch information
Showing
3 changed files
with
48 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,47 @@ | ||
/* @flow strict */ | ||
|
||
// copied from https://github.com/taion/graphql-type-json | ||
import GraphQLJSON from 'graphql-type-json'; | ||
|
||
import { GraphQLScalarType, Kind } from '../graphql'; | ||
export default GraphQLJSON; | ||
|
||
function identity(value) { | ||
return value; | ||
} | ||
|
||
function parseLiteral(ast) { | ||
switch (ast.kind) { | ||
case Kind.STRING: | ||
case Kind.BOOLEAN: | ||
return ast.value; | ||
case Kind.INT: | ||
case Kind.FLOAT: | ||
return parseFloat(ast.value); | ||
case Kind.OBJECT: { | ||
const value = Object.create(null); | ||
ast.fields.forEach(field => { | ||
value[field.name.value] = parseLiteral(field.value); | ||
}); | ||
|
||
return value; | ||
} | ||
case Kind.LIST: | ||
return ast.values.map(parseLiteral); | ||
case Kind.NULL: | ||
return null; | ||
default: | ||
return undefined; | ||
} | ||
} | ||
|
||
export default new GraphQLScalarType({ | ||
name: 'JSON', | ||
description: | ||
'The `JSON` scalar type represents JSON values as specified by ' + | ||
'[ECMA-404](http://www.ecma-international.org/' + | ||
'publications/files/ECMA-ST/ECMA-404.pdf).', | ||
serialize: identity, | ||
parseValue: identity, | ||
parseLiteral, | ||
}); | ||
// import { GraphQLScalarType, Kind } from '../graphql'; | ||
// | ||
// function identity(value) { | ||
// return value; | ||
// } | ||
// | ||
// function parseLiteral(ast) { | ||
// switch (ast.kind) { | ||
// case Kind.STRING: | ||
// case Kind.BOOLEAN: | ||
// return ast.value; | ||
// case Kind.INT: | ||
// case Kind.FLOAT: | ||
// return parseFloat(ast.value); | ||
// case Kind.OBJECT: { | ||
// const value = Object.create(null); | ||
// ast.fields.forEach(field => { | ||
// value[field.name.value] = parseLiteral(field.value); | ||
// }); | ||
// | ||
// return value; | ||
// } | ||
// case Kind.LIST: | ||
// return ast.values.map(parseLiteral); | ||
// case Kind.NULL: | ||
// return null; | ||
// default: | ||
// return undefined; | ||
// } | ||
// } | ||
// | ||
// export default new GraphQLScalarType({ | ||
// name: 'JSON', | ||
// description: | ||
// 'The `JSON` scalar type represents JSON values as specified by ' + | ||
// '[ECMA-404](http://www.ecma-international.org/' + | ||
// 'publications/files/ECMA-ST/ECMA-404.pdf).', | ||
// serialize: identity, | ||
// parseValue: identity, | ||
// parseLiteral, | ||
// }); |
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
e93379e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙇