I'm experimenting with Relay and Graphql and I've got an error message on the browser console:
Warning: RelayQueryWriter: Could not find a type name for record
UHJvZHVjdDpwXzE=.
Here is a runnable example of the issue: https://github.com/brenoc/relay-starter-kit/tree/relay/typenameIssue
This error disappears when I add __typename to the query here:
https://github.com/brenoc/relay-starter-kit/blob/relay/typenameIssue/js/components/App.js#L20
What am I doing wrong?
I got RelayQueryWriter: Could not find a type name for record '1' too in this example:
var appType = new GraphQLObjectType({
name: 'App',
description: 'The application configuration for the current user.',
fields: () => ({
id: {
type: GraphQLID,
description: 'The identifier'
},
email: {
type: new GraphQLNonNull(GraphQLString),
description: 'The user\'s email address'
}
})
});
The 1 is the returned id value from the resolve.
@brenoc could you figure it out?
Are you using the latest version of Relay _and_ babel-relay-plugin? Older versions of the plugin did not add the necessary __typename field, and a version mismatch could cause this issue.
@josephsavona babel-relay-plugin 0.3.0
That is the latest version I guess.
Any ideas what else could be wrong?
Before I used
id: globalIdField('App'),
but that wasn't really what I wanted - or maybe I just don't understand what that id is supposed to be. My assumption is that I can stick the "real" id in there that comes back from my database?
@BerndWessels - Can you paste the fragment from your container?
@josephsavona Yes, I'm using the lastest version of them, v0.4.0 and v0.3.0 (my package.json)
@BerndWessels Unfortunately no, I couldn't :(
@josephsavona
export default Relay.createContainer(App, {
fragments: {
viewer: () => Relay.QL`
fragment on App {
id,
email
}
`
}
});
As @brenoc pointed out, if I add __typename to the requested properties the error goes away - but I expected the system to take care of that?
I've unable to repro this. First I recreated this schema in Relay Playground, but the fragment is fetched and written without error.
I also created an extra test for diffRelayQuery to make sure that the id field wasn't being removed in the diff stage (since the examples above are types that define an id field but do not implement the Node interface).
@brenoc @BerndWessels - Can you create a repro case in Relay Playground to demonstrate this issue?
@josephsavona I have a repo that you can run and see the issue:
https://github.com/brenoc/relay-starter-kit/tree/relay/typenameIssue
It's just a fork of relay-starter-kit with some minor changes in the code. Is that helpful?
Sorry for not providing a case in Relay Playground as you asked. I think it will take some time for me to port that code into Relay Playground.
I think maybe I was just wrong thinking to be able to stick a database id in to object id. It seems that Relay needs type identification within the id to be able to operate. I am still not very comfortable with it, but slowly understand why I can't just put a plain database id into the id property.
Here is a more detailed information about that whole area: http://stackoverflow.com/questions/33399901/in-relay-what-role-do-the-node-interface-and-the-global-id-spec-play
Cheers
@BerndWessels Yes, see also the Node Interface Specification - does implementing the Node interface for these types solve the problem?
That same error:
Warning: RelayQueryWriter: Could not find a type name for record ...
occurs when I bump:
react-relay ^0.5.0 -> ^0.6.0
babel-relay-plugin ^0.4.1 -> ^0.6.0
per #649
@rblakeley can you provide more information? What is the unabbreviated error message? How did you query for that record (i.e. what field did you query that returned it), and what is the schema definition for that field?
Hello
Not sure if this is still related, but all my problems came from trying to fiddle around with the id property of entities.
I tried to use my database ids instead of sticking with the relay generated ids from the nodeDefinitions functions.
So just in case you try the same and end up with errors like the one mentioned in this issue - you should really stick to the relay generated ids and use the nodeDefinitions function to serialize and deserialize.
It took me some time to understand how that all fits together and how to resolve from and to my database objects and ids in relay.
I created a kind of starter-kit that should help to understand how a database like mysql can be plugged in to a react-relay graphql project.
Cheers
Bernd
@josephsavona the unabbreviated error looks like:
Warning: RelayQueryWriter: Could not find a type name for record
client:client:6810115162:UmVzb3VyY2U6NA==.
The app works without issue when I don't bump to 0.6.0. But when I do bump, a specific mutation is triggering the error. The mutation pattern is to create a new item, Group, add the new groupEdge to my User's groups connection, and to add the userEdge to the new Group's users connection.
I am using a central registry for my object types which wraps nodeDefinitions, if that's relevant.
I'm not sure how to answer:
How did you query for that record (i.e. what field did you query that returned it), and what is the schema definition for that field?
...but the relevant files are:
js/components/NewGroupPanel.js
js/mutations/NewGroupMutation.js
data/mutations/NewGroupMutations.js
data/types/GroupType
data/types/UserType
Edit: looks like #653 may get at the same problem
Thanks for filing this - i've identified the missing __typename, will send a fix.
@rblakeley Note that this is just a warning, and Relay will continue to work as-expected when that occurs. At worst, some operations may be _slightly_ less efficient due to the missing typename.
@josephsavona :ok_hand:
the fix is on master and will go out in the next release. thanks for reporting!
I'm still getting this warning, at relay 0.7.1 Warning: RelayQueryWriter: Could not find a type name for record 'VXNlcjox'.
this is the request i make:
initialVariables: {count: 2},
fragments: {
user: () => Relay.QL`
fragment on User {
name
friends(first: $count) {
edges {
cursor
node {
name
}
}
pageInfo {
hasNextPage
}
}
}
`,
}
The VXNlcjox id is the id the User is getting from globalIdField('User')
When i request more friends, the warning appears, my data is:
{
"data": {
"node": {
"_friendsUatc9": {
"edges": [
{
"cursor": "YXJyYXljb25uZWN0aW9uOjI=",
"node": {
"__typename": "Friend",
"name": "resolved heaehraerhaerhaenk",
"id": "RnJpZW5kOjM="
}
},
{
"cursor": "YXJyYXljb25uZWN0aW9uOjM=",
"node": {
"__typename": "Friend",
"name": "resolved heaerhaerhnk",
"id": "RnJpZW5kOjQ="
}
}
],
"pageInfo": {
"hasNextPage": true
}
},
"id": "VXNlcjox"
}
}
}
if i read RelayQueryWriter.prototype.getRecordTypeName correctly, its expecting to get __typename next to the id, but it's not getting it from the node request, and i don't see how i can add it to my node.
Thanks for any help, i hope my code makes it more clear.
When i request more friends, the warning appears
@laurenskling how are you requesting more fields? For example, are you fetching a new query via RelayRootComponent, or are you using setVariables/forceFetch in a component? If the latter, what is the component's fragment?
setVariables:
this.props.relay.setVariables({
count: this.props.relay.variables.count + 2
});
the fragment i posted above, right? This is my route:
user: (Component) => Relay.QL`
query nameQuery {
user {
${Component.getFragment('user')}
}
}
`,
+1
Set Variables:
if(this.props.root.posts.pageInfo.hasNextPage) {
this.setState({
loading: true
});
this.props.relay.setVariables({
count: this.props.relay.variables.count + 20
}, readyState => {
if (readyState.done) {
this.setState({
loading: false,
})
}
});
} else {
if (!this.state.done) {
this.setState({
done: true,
});
}
}
Fragment:
const PostsContainer = Relay.createContainer(Posts, {
initialVariables: {
count: 20,
order: '-id',
filter: null,
},
fragments: {
root: () => Relay.QL`
fragment on Viewer {
id,
posts(first: $count, order: $order, filter: $filter) {
edges {
node {
id,
${PostPreview.getFragment('post')}
}
}
pageInfo {
hasNextPage
}
}
}
`,
},
});
Thanks for the extra info. Reopening to track this.
@josephsavona For some reason, this doesn't throw the warning on Heroku, but only on local development: https://relay-rails-blog.herokuapp.com/
Thanks again for all the info - I think I see what's happening. In both cases, Relay isn't querying for __typename because the type is already known (for @laurenskling the type is User, for @gauravtiwari it's Viewer). We can squash this warning by using the existing information about the type in the store, i'll send a PR.
Note that in the meantime this is just a warning and Relay should be working just fine.
Awesome, glad I could have been of help. Thanks for fixing it!
This should be fixed - feel free to comment if not!
I'm experiencing this in "babel-relay-plugin": "0.11.0", "react-relay": "0.10.0" when using the include directive. When $isMounted is initiated at true from the start, it all works, but when initiate it at false, then after the component mounts, set $isMounted to true, I get the query writer error
I'm not understanding why the ID decoded is User: instead of User:uuid-here
user: () => Relay.QL`
fragment on User {
id
uuid
first_name
is_anonymous
posts(first: $count,
post_type: $post_type,
trade_type: $trade_type,
trade_status: $trade_status)
@include(if: $isMounted) {
pageInfo {
hasNextPage
}
edges {
cursor
node {
id
${MediaItem.getFragment('post')}
}
}
}
${CreatePost.getFragment('viewer')}
}`
