- clone repo
- run
cd GraphQLDemo/GraphQL
- run
dotnet run
(you must have dotnet 6.0+ SDK installed)
The demo app builds a very small database with statements and organisations. Below are some example GraphQL queries you can use:
{
organisations {
nodes {
companyId,
name,
statements {
id,
year
}
}
}
}
In the code, an organisation's address is restricted to users authorised as admin.
[Authorize(Roles = new string[] { "Admin" })]
public string Address { get; set; } = default!;
To be allowed to run the following query:
{
organisations {
nodes {
companyId,
name,
address,
statements {
id,
year
}
}
}
}
You need to create a token and add it as an authorisation header (using bearer).
To do this, go to /api/jwt/admin
and this will generate a JSON Web Token.
You can use token in your request.
You can page your requests using the following queries, see linked documentation (at bottom) for more info.
This gets the first organisation. You will note a token/cursor that is returned.
{
organisations(first:1) {
nodes {
companyId,
name,
address,
statements {
id,
year
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
You can use this token in subsequent queries:
{
organisations(after: "MA==", first:1) {
nodes {
companyId,
name,
address,
statements {
id,
year
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
The following query filters an organisation on its name:
{
organisations (where: {name: { contains: "Big"}}) {
nodes {
id,
companyId,
name,
statements {
id,
year
}
}
}
}