vkolgi / json-to-graphql-query

Simple module that converts JavaScript objects to GraphQL query syntax
MIT License
283 stars 39 forks source link

Use EnumType in Object-Parameter #22

Closed mertins-codamic closed 4 years ago

mertins-codamic commented 4 years ago

Hey @dupski, thank you for this lib. It's exactly what i was looking for. But now i'm stuck by passing EnumTypes in Objects as Parameter.

const query = {
  mutation: {
    create: {
      __aliasFor: 'createPost',
      __args: {
        initial: {title: "XYZ" , status: new EnumType("OPEN")},
      },
      id: true,
    },
  },
};

results in: mutation { create: createPost (initial: {title: "XYZ", status: {value: "OPEN"}}) { id }}

expected: mutation { create: createPost (initial: {title: "XYZ", status: OPEN}) { id }}

Can you help here? Thanks :)

mertins-codamic commented 4 years ago

Additional Info: I figure out why this happens. I used EnumType from other package. (Core-Lib imports json-to-graphql-query and project itself import EnumType, so "instanceof" does not match. Fix it by using: export {EnumType as EnumType} from 'json-to-graphql-query'; in my index.js in Core-Lib.

dupski commented 4 years ago

Glad you sorted it @mertins-codamic :)

tdelabro commented 1 year ago

@dupski I'm having this exact behaviour.

I'm importing import { EnumType } from 'json-to-graphql-query'; in one file, and import { jsonToGraphQLQuery } from 'json-to-graphql-query'; in another one.

See #60