B
B
Bogdnan1232020-10-02 16:06:41
JavaScript
Bogdnan123, 2020-10-02 16:06:41

How to get data and display it on a page from GraphQL?

When I output to the console. I get an error TypeError: Object is not a function

const getData = gql`
  {
    me {
      name,
      id,
    }
  }
`

  const [data, loading, error] = useQuery(getData) 
  console.log(data)


Sandbox: https://coach-tools.dev.pga.com/graphiql

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iamsergo, 2020-10-09
@iamsergo

1) Change the square brackets to curly ones: [] -> {}.
useQuery() returns an object.
2) Also, it is better to use, but not necessarily, such an entry: GET_DATA instead of getData
https://www.apollographql.com/docs/react/data/quer...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question