Variables

Client side

Variables is something that you can use with query or mutation.

First, we need to declare the variable in the operation name.

query MyQuery($username: String) {
	...
}

Next, we want to user that variable with arguments by providing as a value

query MyQuery($username: String) {
	findAllUserByUsername(username: $username) { username }
}

We provide the variable object to server side:

var variables = {  
	username: "Test"  
}

Default variable values

We can provide the default value if we don't want to send the server the variables object in the operation name

query MyQuery($username: String = "Test") {
	findAllUserByUsername(username: $username) { username }
}

Server side

It's the same thing but now we're providing this object as variableValues to our entry point

graphql({ schema, source, rootValue, variableValues: variables }).then((response) => {  
	console.log(JSON.stringify(response, null, 4));  
});