Nicolas B
Nicolas B

Reputation: 315

Graphql : JSON query parameter

I want to send lot of parameters to my query, and i don't want to define it. So i try to pass JSON parameter but i haven't lot of success with it.

I use the https://github.com/taion/graphql-type-json module.

This is my query definition :

usersByParams(params: JSON): [User]

My resolver is :

usersByParams: (_, { params }) => { console.log('PARAMS', params); return users; }

And my query is :

query getUsersByParams {
    usersByParams(params: {test: 'this not work'}) {
        id 
        firstName
        lastName 
        email
        password
    }
}

I my resolvers i always fot "FALSE" value for params. I you have any tips for passing json Thank's

Upvotes: 1

Views: 2252

Answers (1)

Seena V P
Seena V P

Reputation: 994

Add this in your resolver

import GraphQLJSON from 'graphql-type-json';

JSON: {

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

I think this may solve your problem

Upvotes: 1

Related Questions