Iam new to react-native,graphql and Aws AppSync . We tried to build an react-native app using the aws appsync.When i run react-native run-android it is throwing an error saying
passed to parser was not a valid GraphQL DocumentNode.you may need to use 'graphql-tag' or another method to convert your operation into a document
Please do have a look at the
https://i.stack.imgur.com/hr5fA.jpg
image url to get the reference.
import { graphql, compose } from 'react-apollo';
import gql from 'graphql-tag';
const listMessages = graphql(gql`
query listMessages {
listMessages {
id
text
createdAt
sentBy {
id
name
}
}
}`)
const createMessage = graphql(gql`
mutation createMessage($text: String!, $sentById: ID!) {
createMessage(input : {
id : $sentById
text : $text
createdAt : "1/06/2018"
updateAt:"1/06/2018"
}){
sentBy {
id
name
}
}
}`)
export default compose(
graphql(createMessage,{
options: {
fetchPolicy: 'cache-and-network'
}
}, {name : 'createMessageMutation'}),
graphql(listMessages, {
options : {
fetchPolicy: 'cache-and-network'
}
}, {name: 'listMessagesQuery'})
)(Chat)
The above code is the basic implementation of graphql.
I can't really trace out the error Please Help me.Thanks! in advance
You're calling the graphql
function twice -- once in your definition of listMessages
and createMessage
and then again in your export statement. You need to change how your defining the variables you use for your queries:
const createMessage = gql`
mutation createMessage($text: String!, $sentById: ID!) {
createMessage(input : {
id : $sentById
text : $text
createdAt : "1/06/2018"
updateAt:"1/06/2018"
}) {
sentBy {
id
name
}
}
}`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With