I cannot get GraphQL to recognize a scalar JSON type.
I followed [apollo docs] ( http://dev.apollodata.com/tools/graphql-tools/scalars.html#Using-a-package ) to determine the scalar Graphson JSON type for my schema:
Scheme:
const SchemaDefinition = `
scalar JSON
schema {
query: Query
mutation: Mutation
}
`
export default [
SchemaDefinition,
Query,
Mutation,
...
]
Type of test:
const Test = `
type Test {
bodyJson: JSON
}`
Resolver:
import GraphQLJSON from 'graphql-type-json'
const QueryResolver = {
Query: {
viewer(root, args, ctx) {
return User.query()
.where('id', ctx.state.user)
.first()
}
}
}
const scalarJSON = {
JSON: GraphQLJSON
}
export default {
...QueryResolver,
...ViewerResolver,
...scalarJSON
...
}
I am using PostgreSQL, and the column I am querying (body_json) has a jsonb data type.
If I test my schema via GraphiQL when I return the value directly from db (I use Knex for the query), I get this error message from GraphQL:
The expected value is of type \ "JSON \", but received: [object Object]
If I use JSON.stringify first on the return value, I get this error:
" \" JSON\ ", : {\" key\ ": \" test\ "}"
, ?