Reputation: 323
I can't seem to find how to do it in the official GraphQL documentation.
A (very) simple example:
let PostType = new GraphQLObjectType({
name: 'post',
description: 'Represents a blog post',
fields() {
return {
title: {
type: GraphQLString,
args: {
id: {
// HOW CAN I MAKE THIS ARG (id) OPTIONAL
// OR SET A DEFAULT VALUE TO IT?
type: GraphQLString
}
}
}
}
}
});
Upvotes: 2
Views: 6225
Reputation: 84677
From the docs:
type GraphQLArgumentConfig = {
type: GraphQLInputType;
defaultValue?: any;
description?: ?string;
}
So in addition to a type
, just define a defaultValue
for that argument.
Upvotes: 2