import ballerina/graphql;

service /graphql on new graphql:Listener(4000) {

    // The input parameters in a resource function becomes input values of the
    // corresponding GraphQL field. In this GraphQL schema, the 
    // `greeting` field of `Query` type  has a `name`  input value, which accepts
    // `string` values.
    resource function get greeting(string name) returns string {

        return string`Hello, ${name}`;
    }
}

Input Types

GraphQL resources can have input parameters, which will be mapped to input values in the generated GraphQL schema. Currently, the supported input types are: string, int, boolean, float, and enum. Any of these types can be an optional and/or defaultable types.

For more information on the underlying package, see the graphql package.

import ballerina/graphql;
service /graphql on new graphql:Listener(4000) {
    resource function get greeting(string name) returns string {

The input parameters in a resource function becomes input values of the corresponding GraphQL field. In this GraphQL schema, the greeting field of Query type has a name input value, which accepts string values.

        return string`Hello, ${name}`;
    }
}
bal run graphql_input_types.bal
[ballerina/http] started HTTP/WS listener 0.0.0.0:4000
# Send a query to the GraphQL endpoint using a cURL command.
# The query used: { greeting(name: "Walter") }
curl -X POST -H "Content-type: application/json" -d '{ "query": "{ greeting(name: \"Walter\") }" }' 'http://localhost:4000/graphql'
{"data":{"greeting":"Hello, Walter"}}