Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EnumType not working #60

Open
tdelabro opened this issue Dec 9, 2022 · 1 comment
Open

EnumType not working #60

tdelabro opened this issue Dec 9, 2022 · 1 comment

Comments

@tdelabro
Copy link

tdelabro commented Dec 9, 2022

File1:

       import { EnumType } from 'json-to-graphql-query';


        let email = "pierre.fabre@gmail.com";
        let location = { city: "Paris", country: "France", number: "4", postCode: "75008", street: "avenue des Champs Elysee" };
        let identity = { type: new EnumType("PERSON"), optPerson: { firstname: "Pierre", lastname: "Fabre" } };
        let payout_settings = { type: new EnumType("ETHEREUM_ADDRESS"), optEthAddress: "0x123" };

file2:

       import {  jsonToGraphQLQuery } from 'json-to-graphql-query';

       let mutation = jsonToGraphQLQuery({
        mutation: {
            updateProfileInfo: { __args: { email: email, location: location, identity: identity, paytoutSettings: payoutSettings } }
        }
    });
    
    console.log(mutation)

Output:

mutation { updateProfileInfo (email: "pierre.fabre@gmail.com", location: {city: "Paris", country: "France", number: "4", postCode: "75008", street: "avenue des Champs Elysee"}, identity: {type: {value: "PERSON"}, optPerson: {firstname: "Pierre", lastname: "Fabre"}}, paytoutSettings: {type: {value: "ETHEREUM_ADDRESS"}, optEthAddress: "0x123"}) }

You see:
type: {value: "PERSON"} and type: {value: "ETHEREUM_ADDRESS"}
what is expected is type: PERSON and type: ETHEREUM_ADDRESS. This is straight up what the feature is supposed to do.

I'm using "json-to-graphql-query": "2.2.4"

@jnsandrew
Copy link

I'm having the same issue, running v2.2.5. I'm not sure if I'm meant to support this {value: ...} format on the API side, or if it's a problem with this library.

In the meantime, a workaround I've managed to implement is to add my problematic enum under __args rather than __variables. It means your enum will be hardcoded into the query itself rather than sent/validated as a variable.

It's the equivalent of writing:

getPeople(filter: "ALL")...

instead of

getPeople(filter: $filterType)
// variables: {filterType: "ALL"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants