Closed dustinfarris closed 7 years ago
thanks for the bug report! Can you share your schema & query? If not everything, at least the part where it gets tripped up.
Sure!
This is my schema.js which contains everything.
(Note that this is a function because of how I handle importing and passing around graphql)
// graphql/server/schema.js
export default function(graphql) {
const {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLNonNull,
GraphQLID
} = graphql;
const User = new GraphQLObjectType({
name: 'User',
description: 'Stuff',
fields: () => ({
id: {
type: GraphQLID,
description: 'the id'
},
name: {
type: GraphQLString,
description: 'the name'
}
})
});
const queryType = new GraphQLObjectType({
name: 'RootQueryType',
fields: () => ({
hello: {
type: GraphQLString,
resolve() {
return 'world';
}
},
user: {
type: User,
resolve() {
return { id: '123', name: 'Dustin' };
}
}
})
});
return new GraphQLSchema({
query: queryType
});
}
Also, the error gets triggered when I run cashay.query(
{ user })
Running cashay.query(
{ hello })
works fine.
Updated example with a resolve callback. Still getting the same error.
@mattkrick any idea what might be causing this error? i am not too knowledgable on how ASTs work or what exactly is being done by the offending line, but i want to help!
AH! Sorry I replied a few days ago but guess it didn't make it to github. Thanks for the ping!
I think the cause is that you're returning a string instead of a document (complete with an id field). Nevermind, those tests are still working properly. Lemme copy over your example schema & see if i can reproduce.
okie doke, so the problem is that your query isn't valid. GraphQL is super declarative, so you'd need to write:
user {
id
name
}
Otherwise, it doesn't know what fields to grab for ya.
That said, Cashay should probably throw up a useful warning message. I'll fix that
Thanks for the quick feedback. I'll give it a try later today.
Adding the fields works. Thanks!
FYI, if the id
field is omitted, I get this error:
Uncaught TypeError: Cannot read property 'find' of undefined
occurring at this line:
https://github.com/mattkrick/cashay/blob/master/src/normalize/normalizeResponse.js#L52
maybe this needs a friendlier error as well?
that sounds good, i'll add that to the PR
Awesome! Thanks for the quick feedback. I'll make the adjustment, and close after I verify.
Sent from my iPhone
On Oct 23, 2016, at 8:55 AM, Matt Krick notifications@github.com wrote:
okie doke, so the problem is that your query isn't valid. GraphQL is super declarative, so you'd need to write:
user { id name } Otherwise, it doesn't know what fields to grab for ya.
That said, Cashay should probably throw up a useful warning message. I'll fix that
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
Ah, you know what, I don't think I planned for any query from the root query to return a primitive. Usually a query returns a document that includes an ID field. If you don't have an ID, then it can't really cache it efficiently. I'll dig in and see if I can reproduce.
On Fri, Oct 21, 2016, 8:43 AM Dustin Farris notifications@github.com wrote:
Updated example with a resolve callback. Still getting the same error.
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/mattkrick/cashay/issues/131#issuecomment-255412383, or mute the thread https://github.com/notifications/unsubscribe-auth/AFQjv6hwVMrDliRmOJ22jIssM0XrNcA4ks5q2N2ygaJpZM4KdWC0 .
I am bumping in to this error at this line: https://github.com/mattkrick/cashay/blob/8d9174d478b63883f68b64f82c183b60a3aad0c4/src/normalize/denormalizeStore.js#L34
This started happening after I added a custom type to my schema. When i had "hello" resolving to "world" everything worked fine, but when i tried to create a very basic "user" type, i started seeing this.
I'm not sure what's going on here, could use a point in the right direction.