Graphql: Difference between revisions

From wikinotes
 
(28 intermediate revisions by the same user not shown)
Line 5: Line 5:
{| class="wikitable"
{| class="wikitable"
|-
|-
| docs || https://graphql.org/learn/
| official docs || https://graphql.org/learn/
|-
|-
| introspection docs || https://graphql.org/learn/introspection/
| introspection docs || https://graphql.org/learn/introspection/
|-
| graphql spec || http://spec.graphql.org/
|-
|-
|}
|}
</blockquote><!-- documentation -->
</blockquote><!-- documentation -->


= Example =
= Tutorials =
<blockquote>
<blockquote>
Graphql is a language, and it's schema is a large file defining all of the available types, queries, and mutations.
{| class="wikitable"
 
|-
<syntaxhighlight lang="bash">
| digitalocean SDL intro || https://www.digitalocean.com/community/tutorials/graphql-graphql-sdl
# query
|-
curl -X POST \
|}
  -H 'Content-Type: application/json' \
</blockquote><!-- Tutorials -->
  -d '{"query":    "query { members($search: String){ firstName lastName } }", \
      "variables" { "search": "al*" }}' \
  example.com/graphql
</syntaxhighlight>
 
<syntaxhighlight lang="bash">
# mutation
curl -X POST \
  -H 'Content-Type: application/json' \
  -d '{"query":  "mutation { createMember($firstName: String!, $lastName: String!){ ... } }", \
      "variables": { "firstName": "foo", "lastName": "bar" }}' \
  example.com/graphql
</syntaxhighlight>
</blockquote><!-- example -->


= Notes =
= Notes =
<blockquote>
<blockquote>
{|
{|
| [[graphql: basics]]
|-
|-
| [[graphql: usage]]
| [[graphql basics]]
|-
| [[graphql usage]]
|-
|-
| [[graphql: datatypes]]
| [[graphql queries]]
|-
|-
| [[graphql: schemas]]
| [[graphql mutations]]
|-
|-
| [[grpahql: syntax]]
| [[graphql errors]]
|-
|-
|}
|}
</blockquote><!-- notes -->
</blockquote><!-- notes -->


= Clients =
= Syntax =
<blockquote>
<blockquote>
{|
{|
|-
|-
| [[graphql: graphiql]] || web client
| [[graphql datatypes]]
|-
|-
| [[graphqurl]] || cli interpreter
| [[graphql relationships]]
|-
| [[graphql subscriptions]]
|-
|-
|}
|}
</blockquote><!-- clients -->
</blockquote><!-- Syntax -->


= Introspection =
= libraries =
<blockquote>
<blockquote>
== List Types ==
Libraries are mostly used to build APIs. Queries can be performed with regular HTTP requests.
<source lang="bash">
{ __schema { types { name } } }                    # list all types
{ __schema { mutationType { fields { name } } } }  # list all mutations
{ __schema { queryType { fields { name } } } }    # list all queries
</source>


== Query Available Fields ==
{|
<source lang="bash">
|-
{
| [[ruby graphql-ruby]]
  __type(name: "Droid") {  # GraphQL type we want fields from
|-
    name
| [[python ariadne]]
    fields {
|-
      name
| [[python graphene]]
      type {
|-
        name
|}
        kind
</blockquote><!-- Hosting -->
      }
    }
  }
}
</source>
Returns all fields, and their type info.
 
== Query Type info ==
<source lang="bash">
{
  __type(name: "Shop") {
    fields {
      name
      description
    }
  }
}
</source>
</blockquote><!-- tips/tricks -->

Latest revision as of 22:09, 5 September 2021

GraphQL is an alternative to REST APIs that enables you to query exactly what you need using a single HTTP request, rather than several.

Documentation

official docs https://graphql.org/learn/
introspection docs https://graphql.org/learn/introspection/
graphql spec http://spec.graphql.org/

Tutorials

digitalocean SDL intro https://www.digitalocean.com/community/tutorials/graphql-graphql-sdl

Notes

graphql basics
graphql usage
graphql queries
graphql mutations
graphql errors

Syntax

graphql datatypes
graphql relationships
graphql subscriptions

libraries

Libraries are mostly used to build APIs. Queries can be performed with regular HTTP requests.

ruby graphql-ruby
python ariadne
python graphene