Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 840
Bharath Kuppala Avatar asked Nov 08 '22 06:11

Bharath Kuppala


1 Answers

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
      }
    }
 }`
like image 169
Daniel Rearden Avatar answered Nov 15 '22 05:11

Daniel Rearden