A graph consists of a set of nodes and edges which connect pairs of nodes.
N = {F, A, N, B, D}
. The set of edges is E = {FN, NF, FA, AB, BF, BD, DA, NB}
. The graph represented here is called a directed graph because each edge has a direction associated with it. This makes sense for an application like Twitter since, although user F follows user A, it does not necessarily mean that user A follows user F. This is different from an application like Facebook, where connected users are ‘friends’ of each other. In this case, the graph would be undirected and the edges would be drawn without arrows.GET
, POST
, PUT
, DELETE
, and PATCH
. For example, if we wished to retrieve all of the products on an online store for a given category, we would make a GET request to an endpoint that looks something like:http://shopurl.com/api/users/:id
would return something like:Muggles
and Wizards
. However, when we query for a character, we might simply want to look up a Character
by ID or name instead of having to be specific about their magical ability. In this case, we would define an interface:Muggle
and Wizard
types:Character
, but the Wizard
type adds its own field - house
- to its definition. Now we can return a generic Character
when we query for an individual from the frontend, but we're going to run into some trouble with this custom field. We can solve this with an inline fragment."Cannot query field \"house\" on type \"Character\". Did you mean to use an inline fragment on \"Wizard\"?",
character
field returns a generic character, GraphQL may be querying either for a Muggle
or a Wizard
depending on the argument. The problem is the house
field - we are only allowed to query for fields listed on the Character
type.house
field for Wizard
types, we can run our query and retrieve the expected data.