import ballerina/graphql;
// The `graphql:Service` exposes a GraphQL service on the provided port.
service /graphql on new graphql:Listener(4000) {
// A resource function inside a `graphql:Service` represents a resolver.
// This resource can be queried using the `{ greeting }`.
resource function get greeting() returns string {
return "Hello, World";
}
}
Hello worldA GraphQL service in Ballerina represents a GraphQL schema. Each resource function of the |
import ballerina/graphql;
service /graphql on new graphql:Listener(4000) {
The graphql:Service
exposes a GraphQL service on the provided port.
resource function get greeting() returns string {
A resource function inside a graphql:Service
represents a resolver.
This resource can be queried using the { greeting }
.
return "Hello, World";
}
}
bal run graphql_hello_world.bal
# Send a query to the GraphQL endpoint using a cURL command.
# The query used: { greeting }
curl -X POST -H "Content-type: application/json" -d '{ "query": "{ greeting }" }' 'http://localhost:4000/graphql'
{"data":{"greeting":"Hello, World"}}