liztownd/graphql-swapp

GraphQL call sample issues

Closed this issue · 2 comments

// query{

You're on the right track trying to make the call, but a little off on format. Some pointers:

First, the query:
The API doesn't support a name search. It offers only: allPeople, then a person by id:
image

So your initial query would have to pull the people using something like:

query Person($first: Int, $last: Int) {
  allPeople(first: $first, last: $last) {
    people{
      name
      eyeColor
      mass
    }
  }
}

With variables as needed to provide limit and offset in the above:

{
  "last": 3
}

A sample call might look like:

const queryData: {
  query: string;
  variables: Record<string, any>;
} = {
  query: `
    query Collection($key: ID!) {
      dataSet {
        processItem(key: $key) {
          _key
          _id
          _rev
          createdAt
          createdBy
          updatedAt
          updatedBy
          collectionState
          content
          id
          index
        }
      }
    }
  `,
  variables: {},
};

axios.post("/url", queryData)

Sadly, with no name search, you're going to have to query on load then filter on string match in state.

Switched to apollo-client to make the calls, I think this is fixed, but running into a CORS issue so not completely sure...

If they don't support it, you'll not get father using the browser side. This would be a great chance for you to work on making use of full stack in a real application. The server doesn't care about CORS, so we'd likely make the call from there. I think you're far enough given the prototype you're trying out here.