In order to achieve that you would have to define a custom GraphQLScalarType
that returns json
. You can read more about it in custom-scalars.
Or you could just use the package graphql-type-json that basically is an implementation of a GraphQLScalarType
that returns json, something like:
const {GraphQLJSON} = require('graphql-type-json');
const aaa = new GraphQLObjectType({
name: 'aaa',
fields: () => ({
_id: {
type: GraphQLString
},
properties: {
type: GraphQLJSON
},
})
});
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
myField: {
type: aaa,
resolve(parent, args) {
// Here: return your object as it is
// for example:
return {
_id: "this",
properties: {
somerandomname: "asd",
someotherrandomname: "asdad",
"what?!": "it also has strings",
noway: [
"what about them arrays"
]
}
};
}
},
}
})
Then if you query:
{
myField {
_id
properties
}
}
You will get the output:
{
"data": {
"myField": {
"_id": "this",
"properties": {
"somerandomname": "asd",
"someotherrandomname": "asdad",
"what?!": "it also has strings",
"noway": [
"what about them arrays"
]
}
}
}
}