json-to-graphql-query
json-to-graphql-query copied to clipboard
EnumType not working
File1:
import { EnumType } from 'json-to-graphql-query';
let email = "[email protected]";
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: "[email protected]", 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"
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"}