Relyをはじめるには

チュートリアル

Tutorial – チュートリアル（日本語翻訳）

In this tutorial, we will build a game using GraphQL mutations. The object of the game will be to guess where in a grid of 9 squares is hidden some treasure.
We will give players three tries to find the treasure.
This should give us an end-to-end look at Relay – from the GraphQL schema on the server, to the React application on the client.

Authoring a schema – スキーマの作成

A GraphQL schema describes your data model, and provides a GraphQL server with an associated set of resolve methods that know how to fetch data. We will use graphql-js and graphql-relay-js to build our schema.

At this point, you can delete everything up until queryType in ./data/schema.js.

この時点で、./data/schema.js内のqueryTypeの直前まで全て削除できます。

Next, let’s define a node interface and type. We need only provide a way for Relay to map from an object to the GraphQL type associated with that object, and from a global ID to the object it points to:

With the queries out of the way, let’s start in on our only mutation: the one that spends a turn by checking a spot for treasure. Here, we define the input to the mutation (the id of a spot to check for treasure) and a list of all of the possible fields that the client might want updates about after the mutation has taken place. Finally, we implement a method that performs the underlying mutation.