relay: [Modern] relay-compiler errors on mutation
I’ve cloned this repo https://github.com/apollographql/relay-modern-hello-world
by @stubailo and everytime i run yarn run relay
i got this message
Writing default
Error writing modules:
TypeError: type.getFields is not a function
Unchanged: 3 files
Written default in 0.29s
✨ Done in 1.72s.
which i don’t know what TypeError: type.getFields is not a function
means, i got three other queries and they compile perfectly but i can’t get it to work with mutation. I’m not sure if i’m doing something wrong, any help would be greatly appreciated.
This are my files
//src/mutations/CreateCuisineMutation.js
import { commitMutation, graphql } from "react-relay";
const mutation = graphql`
mutation CreateCuisineMutation($name: String!) {
createCuisine(name: $name) {
id
name
}
}
`;
function commit(enviroment, name) {
return commitMutation(enviroment, {
mutation,
variables: { name },
onCompleted: response => {
console.log("Success!");
},
onError: err => console.error(err)
});
}
export default { commit };
This is my schema for cuisine mutations
type Mutation {
createCuisine(name: String!): Cuisine
}
type Cuisine {
id: ID!
name: String!
created: String
updated: String
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (13 by maintainers)
finding something similar when theres no $input value used example (working in graphiQL)
compiler returns undefined
It seems that relay-compiler is trying to get each argument from the ast and get it’s fields, given that i get
TypeError: type.getFields is not a function
and my String inmutation CreateCuisineMutation($name: String!)
has no fieldsYeah, I think this is just a bug as @mjmahone mentioned. Do you have the full stack trace of the error?
Note that Relay Modern relaxes all the restrictions from Relay classic for mutations:
clientMutationId
fieldPlease file bugs / send PRs if this isn’t working! Stack trace would help in this case.
Closing in favor of the 2 linked issues.
Hey @henryqdineen, sorry for the delay, it seems that the compiler only works with input type objects, so
String!
,Int!
, etc will not work for nowMy guess is that mutations have to follow the GraphQL Relay spec in that regard and this is still a requirement with Modern:
Great article on designing mutations which happen to align with the relay spec and give you some perspective as to why it’s a good idea: https://dev-blog.apollodata.com/designing-graphql-mutations-e09de826ed97