简体   繁体   中英

Apollo-GraphQL error when sending word with space?

I have a GQL Apollo which filters by a state. The GQL takes values like "ACCEPTED" or "DECLINED" etc. However, I noticed that when i send a filter like "GOOD LEAVER" which has a space it won't work anymore. Any ideeas? I get this error

Stack: GraphQLError: Variable "$stateIn" got invalid value ["GOOD LEAVER"].
In element #0: Expected type "MemberStateType", found "GOOD LEAVER".

to send this variable i am using a util function to take the values from props, the function is

stateIn:
  getFilterProp('status') &&
  getOr([], 'status', selectedFilterOptions).map(({ name }) =>
    toUpper(name)
)

I am 100% percent the value gets send because I can see them in the networks tab, it just throws the above error when I want to use the filter "GOOD LEAVER", otherwise, it works just fine.

From the context, I'm assuming the type of your $stateIn variable is [MemberStateType] and that MemberStateType is an enum. As the error indicates, GOOD LEAVER is not a valid value for this enum. Enum values must be valid GraphQL names, so they must match the following regex:

/[_A-Za-z][_0-9A-Za-z]*/

However, the point is not that you're passing in a name with a space -- the point is that you're passing in a value that doesn't match the possible values for the enum as it's defined in the schema. If you passed in a value like FWaFJRYyTPx or some other invalid enum value, you'd see a similar error.

Consult the schema for the GraphQL endpoint to determine the valid enum values and transform your input accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM