Reputation: 166
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
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
Upvotes: 7
Views: 19733
Reputation: 799
You can use only GQL to define your queries.
You can use either.
No need to add graphql.
import gql from 'graphql-tag';
const listMessages = gql
query listMessages {
listMessages {
id
text
createdAt
sentBy {
id
name
}
}
}
Upvotes: 1
Reputation: 84687
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
}
}
}`
Upvotes: 1