Reputation: 363
What does a resolver function look like that returns an enum in graphql-yoga? 🧘♀️ I can't find any examples in their docs.
query{
search() : CreateUrlResponse!
}
type CreateUrlResponse {
searchResult: String!
error: CreateUrlError
}
enum CreateUrlError {
Error1
Error2
}
resolver :
export const query = {
async search(parent, args, ctx: Context, info) {
???
}
}
Upvotes: 3
Views: 375
Reputation: 84687
An enums in GraphQL.js are effectively just a String that's just limited to some set of values. So you can just do:
return {
searchResult: 'Foo',
error: 'Error1',
}
Note: when using them in a request, their behavior will be slightly different:
someQuery(someString: "Foo")
someOtherQuery(someEnum: Foo)
Upvotes: 0
Reputation: 7808
This should work:
export const query = {
search(parent, args, ctx: Context, info) {
return {
searchResult: "abc",
error: "Error1",
}
}
}
Upvotes: 2