graphql-go / relay

A Go/Golang library to help construct a graphql-go server supporting react-relay.
MIT License
424 stars 58 forks source link

IDFetcher to return error #17

Closed bsr203 closed 8 years ago

bsr203 commented 8 years ago

Currently, there is no way to return an error from idFetcher function. error return type of the resolve methos is not used https://github.com/graphql-go/relay/blob/master/node.go#L56

We should be changing the type from

type IDFetcherFn func(id string, info graphql.ResolveInfo) interface{}

to 

type IDFetcherFn func(id string, info graphql.ResolveInfo) (interface{}, error)

so we can return the error from IDFetcher by just returning

https://github.com/graphql-go/relay/blob/master/node.go#L64 could be just

return config.IDFetcher(id, p.Info)
F21 commented 8 years ago

:+1: for this. After working with graphql-go for the last few weeks, I feel this is something that's quite necessary.

Because we are switching on resolvedID.Type and resolvedID.ID and using that to fetch the model, if the model fails to fetch, we need to return an error instead.

F21 commented 8 years ago

@sogko Any comments on this one?

sogko commented 8 years ago

@F21 Thanks for bringing this up. Actually this does make sense, since we already have a way to return error within graphql-go.

I'll go ahead and submit a PR soon.

Thanks!