JSON type in GraphQL
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[ ] Feature request
[X] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
https://www.apollographql.com/docs/graphql-tools/scalars.html Is it possible to implement JSON as a GraphQL type using graphql-type-json or any other package or way? Sorry I haven’t found any thread or examples on this, so wondering if its possible to do in nest like its done in Express
My GraphQL Module
GraphQLModule.forRoot({
typePaths: ['./**/*.graphql'],
installSubscriptionHandlers: true,
definitions: {
path: join(process.cwd(), 'src/graphql.schema.ts'),
outputAs: 'class',
},
context: ({ req }) => ({ headers: req.headers, req: req }),
}),
Is it possible to include the type resolvers here ?
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
JSON scalar type for GraphQL.js - GitHub
GraphQLJSON can represent any JSON-serializable value, including scalars, arrays, and objects. GraphQLJSONObject represents specifically JSON objects, ...
Read more >Custom scalars - Apollo GraphQL Docs
For example, the graphql-type-json package defines the GraphQLJSON object, which is an instance of GraphQLScalarType . You can use this object to define...
Read more >Class: GraphQL::Types::JSON
An untyped JSON scalar that maps to Ruby hashes, arrays, strings, integers, floats, booleans and nils. This should be used judiciously because it...
Read more >Assigning JSON in a GraphQL type in Nodejs - Stack Overflow
In that case, I need a another type (which should be a JSON type) to map these responses. Unfortunately, it is not available...
Read more >Schemas and Types - GraphQL
On this page, you'll learn all you need to know about the GraphQL type system and how it describes what data can be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
JSON type for the code first approach. This works in my environment,
"@nestjs/graphql": "^7.3.7"
.Then you see the following in your
schema.gql
.ok guys… i managed to solve this issue. However, i was not able to directly include any of the existing packages (although this may be possible for sure).
Here is, what i did: First, i had to create a plain
JSONObject
class like this:Then, i created a new
Scalar
for thisJSONObject
i want to outputThen i “registered” this
Scalar
somewhere (for example in the module i want to use it):and finally use the newly defined
Scalar
in anObjectType()
orInputType()
like so:I really hope, this helps someone. Downside, with this approach is, that you need a dedicated
JSONObject
class. I was not able to useObject
(orobject
) to achieve the same. Anyway - this works for me 😉All the best