GraphQL
GraphQL (Graph Query Language) is an open-source query language for APIs. It's used by GitHub, Shopify, and Facebook internally.
- GraphQL Documentation (βͺ)
- GitHub (19.8k β)
It was designed to provide a more efficient, powerful, and flexible alternative to traditional REST APIs.
To query the id,username
of the user
with id=123
:
query {
user(id: 123) {
id
username
}
}
Introspection πΊοΈ
Each object has a type. Each type has attributes. The type may have a constructor with arguments that are required to query an object.
{__schema{types{name}}}
{__schema{types{name,fields{name}}}}
{__schema{types{name,fields{name},description}}}
{__schema{types{name,fields{name,args{name,description,type{name,kind,ofType{name, kind}}}}}}}
After identifying the types and their arguments, we can query them:
{MyType{field1, field2}}
{MyType(arg:value){field1, field2}}