Skip to content

Latest commit

 

History

History
102 lines (86 loc) · 2.43 KB

File metadata and controls

102 lines (86 loc) · 2.43 KB

The best way to learn how GraphQL works is to try it out. Let's start by playing with GraphiQL, a powerful developer tool for testing out queries:

https://www.opentable.com/graphiql

Copy the following query into the editor and hit the execute button:

{
  restaurant(restaurantId: 1906) {
    name
  }
}

You should get a JSON response which matches your query:

Simple restaurant query

Let's extend our restaurant query to get a feel for the GraphiQL editor; try pressing Ctrl-Space after the restaurant name to see what fields are available:

GraphiQL intellisense

How about getting the restaurant cuisines:

{
  restaurant(restaurantId: 1906) {
    name
    cuisines {
      name
    }
  }
}

After executing the query you will see a list of cuisines for the restaurant:

Restaurant with cuisines query

GraphiQL's intellisense feature is an excellent way to discover the capabilities of a GraphQL API, but it's also worth taking a look at the Documentation Explorer by clicking on the "Docs" button in the top right corner:

GraphiQL documentation explorer

Have a play with the API, explore the schema and see what queries you can write. If you get stuck try adapting the following complex query:

{
  restaurant(restaurantId: 1906) {
    name
    cuisines {
      name
    }
    priceBand {
      name
    }
    country {
      name
    }
    metro {
      name
    }
    macro {
      name
    }
    neighborhood {
      name
    }
    messages {
      standardMessages {
        confirmation {
          message
        }
      }
    }
    menus {
      title
      sections {
        items {
          title
        }
      }
    }
    reviews(offset: 0, limit: 2) {
      description
      rating {
        overall
      }
    }
  }
  metro (metroId: 4) {
    name
    pointsOfInterest {
      name
    }
  }
}

Learn more here: