type-graphql: Error when using GraphQLJSON
The latest version (0.15.0) seems to have issues with custom scalars such as the JSON type provided by the GraphQLJSON package (graphql-type-json).
Here is a basic example of what I’d like to do:
import { ObjectType, Field } from "type-graphql";
import GraphQLJSON = require("graphql-type-json");
@ObjectType()
export default class MyData {
@Field(type => GraphQLJSON)
public jsonData: any;
}
This results in the following error: “Error: Cannot determine GraphQL input type for jsonData”.
When I go back to the previous version (0.14.0) and GraphQL version 0.13.2, the error disappears and my code works again.
Environment:
- OS: Mac, Windows
- Node: 10.12.0
- Package version: 0.15.0
- TypeScript version: 3.1.4
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18 (8 by maintainers)
@darkmantle
Setting:
Means you should use default import:
No, you need to have only one version of
graphql-js
in your project, otherwise you will have the “another realm” error.The
type instanceof GraphQLScalarType
checks also seems to cause issues if youyarn link
into another project that has a different version ofgraphql
installed. Would it make sense to usetype.constructor.name
checks here to guard against this?Thanks for your response! After making this change it works 😃.
According to the code: https://github.com/taion/graphql-type-json/blob/5790abc351b3007dc9dc98ccf35e9ea72ed7ba91/src/index.js#L37
You should do:
import GraphQLJSON = require("graphql-type-json").default
;But as I’ve tried in reproduction repo: https://gitlab.com/esindger/tgql-scalar-example
You should do:
import * as GraphQLJSON from "graphql-type-json";
instead of:import GraphQLJSON from "graphql-type-json";
Then it works 😃