Hot Chocolatev13

Arguments

GraphQL allows us to specify arguments on a field and access their values in the field's resolver.

SDL
type Query {
user(id: ID!): User
}

Clients can specify arguments like the following.

GraphQL
{
user(id: "123") {
username
}
}

Often times arguments will be specified using variables.

GraphQL
query ($userId: ID!) {
user(id: $userId) {
username
}
}

Learn more about arguments here and variables here.

Usage

Arguments can be defined like the following.

C#
public class Query
{
public User GetUser(string username)
{
// Omitted code for brevity
}
}

We can also change the name of the argument used in the schema.

C#
public class Query
{
public User GetUser([GraphQLName("name")] string username)
{
// Omitted code for brevity
}
}

Arguments can be made required by using the non-null type. Learn more about non-null

If we need to provide complex objects as arguments, we can use input object types.