2

I'm working on an apollo-express graphql server. I attempted to integrate the module 'graphql-type-json' but when I followed this description on how to integrate, I've tried many things but it seems that the type isn't being passed to the resolver correctly - but I've hit a wall in my debugging and could use a little help. Here is a summary of what I'm doing.

import { makeExecutableSchema } from 'graphql-tools';
const GraphQLJSON = require('graphql-type-json');
//Have also tried import GraphQLJSON from 'graphql-type-json';

const schema = `
scalar JSON

type Device {
  deviceconfig: JSON
}

type Query {
  foo: Foo
}
`;

const resolveFunctions = {
   JSON: GraphQLJSON,
   //JSON: {return GraphQLJSON} stops error but other issues come up...
   Query: ...
 };

const jsSchema = makeExecutableSchema({
typeDefs: schema,
resolvers: resolveFunctions,
resolverValidationOptions: {
  requireResolversForNonScalar: false,
},
allowUndefinedInResolve: true,
printErrors: true,
});

Not sure if it's relevant but there are a few issues with my npm:

graphql-type-json@0.1.4

UNMET PEER DEPENDENCY graphql@0.8.2 invalid

├─┬ graphql-tools@0.4.2

│ ├── UNMET PEER DEPENDENCY graphql@^0.5.0 || ^0.6.0


npm ERR! peer dep missing: graphql@^0.6.1 || ^0.7.0, required by apollo-server@0.3.3

npm ERR! peer dep missing: graphql@^0.5.0, required by graphql-tools@0.4.2

npm ERR! extraneous: casual@1.5.8 /home/apollo/node_modules/casual

npm ERR! extraneous: mongoose@4.6.6 /home/apollo/node_modules/mongoose

npm ERR! extraneous: mysql-events@0.0.8 /home/apollo/node_modules/mysql-events

npm ERR! peer dep missing: graphql@^0.5.0 || ^0.6.0, required by express-widgetizer@0.5.11
Cameron
  • 2,574
  • 22
  • 37
RobotBox2000
  • 23
  • 1
  • 5
  • "(node:5338) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: type.getFields is not a function" is the exact warning I get – RobotBox2000 Jan 27 '17 at 20:42
  • I'd suggest upgrading to the newest versions of `graphql-tools` and `graphql`, and use the newest `graphql-server-express`, which is the new name for `apollo-server`. It might be some weird interaction of dependencies. – stubailo Mar 22 '17 at 05:01

1 Answers1

1

I resolved custom scalar JSON like this in resolvers

 JSON: {

    __serialize(value) {
        return GraphQLJSON.parseValue(value);
    } }

And It worked fine for me. I think it will help you

Seena V P
  • 934
  • 3
  • 9
  • 26