You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perNight: {resolve: async({ id },args,ctx: Context,info)=>{constplace=awaitctx.db.query.place({where: { id }},"{ pricing { perNight } }")returnplace.pricing.perNight},},
And perNight: Int! to the Home type in schema.graphql
Then running this query in the playground
{
topHomes {
perNight
}
}
returns the error
"Field 'places' of type 'Place' must have a sub selection. (line 2, column 3):\n places(where: $_where, orderBy: $_orderBy, skip: $_skip, after: $_after, before: $_before, first: $_first, last: $_last)\n ^"
but this query works as expected
{
topHomes {
perNightid
}
}
The text was updated successfully, but these errors were encountered:
Thanks a lot for bringing this up! The reason is that the resolver itself assumes the existence of an id (you can see this in the first argument which is { id }). So, if there is no id after all, an error is returned (the error message is not too helpful though).
You can solve this use case by providing a fragment option to the resolver object, which ensures that id is part of the query.
This same situation is already handled in the numRatings field of the Home type:
numRatings: {fragment: `fragment NumRatings on Place { id }`,resolve: async({ id },args,ctx: Context,info)=>{const places =awaitctx.db.query.places({where: { id }})returnplaces.length},},
So applying that same logic to perNight leaves us with this:
perNight: {fragment: `fragment pricing on Place { id }`,resolve: async({ id },args,ctx: Context,info)=>{const place =awaitctx.db.query.place({where: { id }},"{ pricing { perNight } }")returnplace.pricing.perNight},},
I added this property to Home in https://github.com/graphcool/graphcool-server-example/blob/master/src/resolvers/Home.ts
And
perNight: Int!
to the Home type in schema.graphqlThen running this query in the playground
returns the error
but this query works as expected
The text was updated successfully, but these errors were encountered: