### Complete Mock Server Example Source: https://github.com/graphql/graphql.github.io/blob/source/src/pages/blog/2016-04-19-mocking.mdx A full example demonstrating schema definition, mock function setup, and a sample query. ```APIDOC ## Complete Mock Server Example ### Description This example integrates schema definition, mock function setup using `graphql-tools` and `casual`, and a sample GraphQL query to test the mock server. ### Method N/A (Configuration & Query) ### Endpoint N/A (Configuration & Query) ### Parameters N/A ### Request Example ```javascript import { mockServer, MockList } from "graphql-tools" import casual from "casual-browserify" // The GraphQL schema. const schema = ` type User { id: ID! name: String lists: [List] } type List { id: ID! name: String owner: User incomplete_count: Int tasks(completed: Boolean): [Task] } type Task { id: ID! text: String completed: Boolean list: List } type RootQuery { user(id: ID): User } schema { query: RootQuery } ` // Mock functions are defined per type and return an // object with some or all of the fields of that type. const server = mockServer(schema, { RootQuery: () => ({ user: (o, { id }) => ({ id }), }), List: () => ({ name: () => casual.word, tasks: () => new MockList(4, (o, { completed }) => ({ completed })), }), Task: () => ({ text: casual.words(10) }), User: () => ({ name: casual.name }), }) mockServer.query(` query tasksForUser{ user(id: 6) { id name lists { name completeTasks: tasks(completed: true) { completed text } incompleteTasks: tasks(completed: false) { completed text } anyTasks: tasks { completed text } } } }`) ``` ### Response N/A (Response depends on the query executed against the mock server) ``` -------------------------------- ### Apollo Server Hello World Example Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/server/apollo-server.md A basic 'hello world' example demonstrating how to create and start a GraphQL server using Apollo Server. It defines a simple schema with a 'hello' query and a resolver function to return 'world'. ```javascript import { ApolloServer } from "@apollo/server" import { startStandaloneServer } from "@apollo/server/standalone" // The GraphQL schema const typeDefs = `#graphql type Query { hello: String } ` // A map of functions which return data for the schema. const resolvers = { Query: { hello: () => "world", }, } const server = new ApolloServer({ typeDefs, resolvers, }) const { url } = await startStandaloneServer(server) console.log(`🚀 Server ready at ${url}`) ``` -------------------------------- ### Express GraphQL Server Implementation (JavaScript) Source: https://github.com/graphql/graphql.github.io/blob/source/notes/ContributingToCodePage.md This example demonstrates how to set up a basic GraphQL API server using Express and graphql-http in Node.js. It includes installation instructions and the server code. ```sh npm install express graphql-http graphql ``` ```js var express = require("express") var { createHandler } = require("graphql-http/lib/use/express") var { buildSchema } = require("graphql") var schema = buildSchema(/* GraphQL */ ` type Query { hello: String } `) var root = { hello: () => "Hello world!" } var app = express() app.all( "/graphql", createHandler({ schema: schema, rootValue: root, }), ) app.listen(4000, () => console.log("Now browse to localhost:4000/graphql")) ``` -------------------------------- ### Install GraphQL.js Source: https://github.com/graphql/graphql.github.io/blob/source/src/pages/graphql-js/index.mdx Installs the GraphQL.js library and initializes a new Node.js project. This is a prerequisite for running GraphQL applications. ```bash npm init npm install graphql --save ``` -------------------------------- ### Install and Configure DataLoader Source: https://github.com/graphql/graphql.github.io/blob/source/src/pages/blog/2016-05-02-rest-api-graphql-wrapper.mdx Demonstrates how to install the DataLoader library and initialize it to batch and memoize requests to a REST API, reducing redundant network calls. ```bash npm i dataloader ``` ```javascript const personLoader = new DataLoader(urls => Promise.all(urls.map(fetchPersonByURL)) ); ``` -------------------------------- ### Hello World GraphQL API with Mercurius and Fastify Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/server/mercurius.md Sets up a simple 'Hello World' GraphQL endpoint using Mercurius and Fastify. It defines a GraphQL schema, implements resolvers, registers the Mercurius plugin with Fastify, and starts the server. This example shows the basic structure for creating a GraphQL API. ```javascript const Fastify = require("fastify") const mercurius = require("mercurius") const schema = ` type Query { hello(name: String): String! } ` const resolvers = { Query: { hello: async (_, { name }) => `hello ${name || "world"}`, }, } const app = Fastify() app.register(mercurius, { schema, resolvers, }) app.listen(3000) // Call IT! // curl 'http://localhost:3000/graphql' \ // -H 'content-type: application/json' \ // --data-raw '{"query":"{ hello(name:\"Marcurius\") }" }' ``` -------------------------------- ### Install and Run SpectaQL Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/tools/spectaql.md Installs SpectaQL as a development dependency using npm or yarn and demonstrates how to generate documentation using a configuration file. ```sh npm install --dev spectaql # OR yarn add -D spectaql # Then generate your docs npm run spectaql my-config.yml # OR yarn spectaql my-config.yml ``` -------------------------------- ### Install and Initialize Django Project Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/python/server/django-graphbox.md Commands to install the django-graphbox package and initialize a standard Django project structure. ```bash pip install django-graphbox django-admin startproject myproject cd myproject python manage.py startapp myapp ``` -------------------------------- ### Install and Run GraphQL Ruby Hello World Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/ruby/server/graphql-ruby.md This snippet shows how to install the graphql-ruby gem and run a basic 'Hello, world!' GraphQL schema. It requires Ruby and the gem to be installed. The output is a JSON string representing the result of the GraphQL query. ```bash gem install graphql ``` ```ruby require 'graphql' class QueryType < GraphQL::Schema::Object field :hello, String def hello "Hello world!" end end class Schema < GraphQL::Schema query QueryType end puts Schema.execute('{ hello }').to_json ``` -------------------------------- ### Integrate KGraphQL with Ktor Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/java-kotlin-android/server/kgraphql.md Shows how to install the KGraphQL plugin into a Ktor application. This setup enables a GraphQL server and includes the GraphQL playground IDE for testing. ```kotlin fun Application.module() { install(GraphQL) { playground = true schema { query("hello") { resolver { -> "World!" } } } } } ``` -------------------------------- ### Install Qlient Python Library Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/python/client/qlient.md This command installs the Qlient library using pip. Qlient is a fast and modern GraphQL client for Python. ```bash pip install qlient ``` -------------------------------- ### Pylon Development Example Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/server/pylon.md An example of how to define a GraphQL schema and resolvers using Pylon. ```APIDOC ## Pylon Development Example ### Description This example demonstrates defining a GraphQL schema with queries and mutations in Pylon. ### Method TypeScript ### Endpoint N/A ### Request Body ```typescript import { app } from "@getcronit/pylon" class User { name: string email: string constructor(name: string, email: string) { this.name = name this.email = email } } const users = [ new User("Alice", "alice@example.com"), new User("Bob", "bob@example.com"), new User("Charlie", "charlie@example.com"), ] export const graphql = { Query: { users, user: (name: string) => { return users.find(user => user.name === name) }, }, Mutation: { addUser: (name: string, email: string) => { const user = new User(name, email) users.push(user) return user }, }, } export default app ``` ### Response N/A ``` -------------------------------- ### Install GraphQL Dependencies Source: https://github.com/graphql/graphql.github.io/blob/source/src/pages/graphql-js/running-an-express-graphql-server.mdx Command to install the required packages for running a GraphQL server with Express. ```bash npm install express graphql-http graphql --save ``` -------------------------------- ### Install and Use GraphQLClient.jl Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/julia/client/graphqlclient-jl.md Demonstrates how to install the GraphQLClient.jl package using Julia's package manager and how to import it for use. This is the initial step before connecting to a GraphQL server. ```julia using Pkg; Pkg.add("GraphQLClient") using GraphQLClient ``` -------------------------------- ### Install Graphene Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/python/server/graphene.md Installs the Graphene library, a Python tool for building GraphQL APIs. This is a prerequisite for running Graphene applications. ```bash pip install graphene ``` -------------------------------- ### Install ql GraphQL Client Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/python/client/ql.md Installation instructions for the ql library using pip. This package is required to enable Pydantic-based GraphQL querying in your Python project. ```console pip3 install pydantic-graphql ``` -------------------------------- ### Install Fastify and Mercurius Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/server/mercurius.md Installs the necessary packages, Fastify and Mercurius, for building a GraphQL API. ```bash npm install fastify mercurius ``` -------------------------------- ### Install Strawberry GraphQL Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/python/server/strawberry.md Installs the Strawberry GraphQL library using pip. This is the first step to using Strawberry for building GraphQL servers in Python. ```bash pip install strawberry-graphql ``` -------------------------------- ### Install GraphQL Yoga and Dependencies Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/server/graphql-yoga.md Installs the necessary packages for GraphQL Yoga, including the core library and GraphQL itself. This is a prerequisite for running a GraphQL Yoga server. ```bash npm install graphql-yoga graphql ``` -------------------------------- ### Install GraphQL dependencies Source: https://github.com/graphql/graphql.github.io/blob/source/src/pages/blog/2016-05-02-rest-api-graphql-wrapper.mdx Installs the necessary graphql package to begin building a schema. This is a prerequisite for defining types and resolvers. ```bash npm i graphql ``` ```yarn yarn add graphql ``` -------------------------------- ### Install Apollo Server and GraphQL Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/server/apollo-server.md Installs the necessary packages for running an Apollo Server GraphQL application. This includes the core Apollo Server library and the graphql package. ```bash npm install @apollo/server graphql ``` -------------------------------- ### Python Qlient Hello World Example Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/python/client/qlient.md This Python script demonstrates a basic 'hello world' example using the Qlient library to query the SWAPI GraphQL API. It shows how to initialize an HTTP client, execute a query, and access the response data, request query, and variables. ```python from qlient.http import HTTPClient, GraphQLResponse client = HTTPClient("https://swapi-graphql.netlify.app/.netlify/functions/index") res: GraphQLResponse = client.query.film( # swapi graphql input fields id="ZmlsbXM6MQ==", # qlient specific _fields=["id", "title", "episodeID"] ) print(res.request.query) # query film($id: ID) { film(id: $id) { id title episodeID } } print(res.request.variables) # {'id': 'ZmlsbXM6MQ=='} print(res.data) # {'film': {'id': 'ZmlsbXM6MQ==', 'title': 'A New Hope', 'episodeID': 4}} ``` -------------------------------- ### Run Python Qlient Example Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/python/client/qlient.md This command executes the Python script that uses the Qlient library to interact with the SWAPI GraphQL API. ```bash python swapi_client_example.py ``` -------------------------------- ### Full GraphQL Server Implementation Source: https://github.com/graphql/graphql.github.io/blob/source/src/pages/graphql-js/passing-arguments.mdx A complete Express.js server setup for a GraphQL API. It uses 'graphql-http' to handle requests, defines the schema with arguments, and implements the 'rollDice' resolver. Includes starting the server and logging its address. ```javascript import express from "express"; import { createHandler } from "graphql-http/lib/use/express"; import { buildSchema } from "graphql"; // Construct a schema using GraphQL schema language const schema = buildSchema(/* GraphQL */ ` type Query { rollDice(numDice: Int!, numSides: Int): [Int] } `); // The root provides a resolver function for each API endpoint const root = { rollDice({ numDice, numSides }) { const output = []; const sides = numSides || 6; for (let i = 0; i < numDice; i++) { output.push(1 + Math.floor(Math.random() * sides)); } return output; }, }; const app = express(); app.all( "/graphql", createHandler({ schema, rootValue: root, }) ); app.listen(4000, () => { console.log("Running a GraphQL API server at localhost:4000/graphql"); }); ``` -------------------------------- ### Pylon Setup Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/server/pylon.md Instructions on how to create a new Pylon project. ```APIDOC ## Pylon Setup ### Description Use the following command to create a new Pylon project. ### Method Command Line ### Endpoint N/A ### Request Example ```bash npm create pylon@latest ``` ### Response N/A ``` -------------------------------- ### Install Lychee for Link Checking Source: https://github.com/graphql/graphql.github.io/blob/source/CONTRIBUTING.md Install Lychee, a Rust-based CLI tool for checking broken links, after installing Rust. This command installs Lychee globally. ```bash cargo install lychee ``` -------------------------------- ### Install and Run GraphQL.js Hello World Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/server/graphql-js.md This snippet demonstrates how to install the graphql package and execute a simple GraphQL query in Node.js. It requires Node.js and npm. The input is a GraphQL query string, and the output is the JSON response from the server. ```bash npm install graphql ``` ```javascript var { graphql, buildSchema } = require("graphql") var schema = buildSchema(` type Query { hello: String } `) var rootValue = { hello: () => "Hello world!" } var source = "{ hello }" graphql({ schema, source, rootValue }).then(response => { console.log(response) }) ``` -------------------------------- ### Run Eggql Hello World Server in Go Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/go/server/andrewwphillips-eggql.md This Go program demonstrates how to set up a basic Eggql GraphQL server. It creates a root Query object with a 'message' field and listens for HTTP requests on port 80. Dependencies include the eggql library. ```Go package main import "github.com/andrewwphillips/eggql" import "net/http" func main() { http.Handle("/graphql", eggql.New(struct{ Message string }{Message: "hello, world"})) http.ListenAndServe(":80", nil) } ``` -------------------------------- ### Install Graphene Django CRUDDALS Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/python/server/graphene-django-cruddals.md This command installs the graphene-django-cruddals package using pip. Ensure you have pip installed and configured correctly. ```bash pip install graphene-django-cruddals ``` -------------------------------- ### Installation Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/python/server/graphene-django-cruddals.md Install the graphene-django-cruddals package using pip. ```APIDOC ## Installation ### Description Install the graphene-django-cruddals package using pip. ### Method bash ### Endpoint ### Parameters ### Request Body ### Request Example ### Response #### Success Response (200) #### Response Example ```bash pip install graphene-django-cruddals ``` ``` -------------------------------- ### Create a Mock GraphQL Server Source: https://github.com/graphql/graphql.github.io/blob/source/src/pages/blog/2016-04-19-mocking.mdx Demonstrates how to initialize a mock server using a GraphQL schema file. This approach automatically generates mock data for any valid query based on the schema definitions. ```javascript import { mockServer } from "graphql-tools"; import schema from "./mySchema.graphql"; const myMockServer = mockServer(schema); myMockServer.query(`{ allUsers: { id name } }`); ``` -------------------------------- ### Install graphql_query library Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/python/client/graphql-query.md The command to install the graphql_query package via pip. ```shell $ pip install graphql_query ``` -------------------------------- ### Install graphql-hooks package Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/client/graphql-hooks.md The command to install the graphql-hooks library via npm. ```bash npm install graphql-hooks ``` -------------------------------- ### Pylon Query Examples Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/server/pylon.md Examples of GraphQL queries and mutations that can be executed against a Pylon API. ```APIDOC ## Pylon Query Examples ### Description Examples of GraphQL queries and mutations for interacting with a Pylon API. ### Method GraphQL ### Endpoint N/A ### Request Example ```graphql query User { user(name: "Alice") { name email } } query Users { users { name email } } mutation AddUser { addUser(name: "Corina", email: "corina@example.com") { name email } } ``` ### Response N/A ``` -------------------------------- ### Create a Hello World GraphQL Yoga Server (JavaScript) Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/server/graphql-yoga.md Demonstrates how to create a simple GraphQL server using GraphQL Yoga. It defines a basic schema with a 'hello' query and starts an HTTP server listening on port 4000. ```javascript import { createServer } from "http" import { createSchema, createYoga } from "graphql-yoga" createServer( createYoga({ schema: createSchema({ typeDefs: /* GraphQL */ ` type Query { hello: String } `, resolvers: { Query: { hello: () => "Hello Hello Hello", }, }, }), }), ).listen(4000, () => { console.info("GraphQL Yoga is listening on http://localhost:4000/graphql") }) ``` -------------------------------- ### Install Tartiflette Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/python/server/tartiflette.md Installs the Tartiflette library using pip. This is a prerequisite for running Tartiflette applications. ```sh pip install tartiflette ``` -------------------------------- ### Initialize Pylon Project Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/server/pylon.md Use the Pylon CLI to scaffold a new project. This command sets up the necessary environment to start building your GraphQL API. ```bash npm create pylon@latest ``` -------------------------------- ### Initialize GQty Project Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/client/gqty.md Commands to initialize a GQty project using various package managers. These commands trigger the interactive CLI to set up the environment and generate necessary types. ```bash # npm npx @gqty/cli # yarn yarn dlx @gqty/cli # pnpm pnpm dlx @gqty/cli ``` -------------------------------- ### Install Ariadne Codegen Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/python/client/ariadne-codegen.md Installs the Ariadne Codegen package using pip. This is a prerequisite for generating GraphQL clients. ```bash $ pip install ariadne-codegen ``` -------------------------------- ### Complete GraphQL Mock Server Implementation Source: https://github.com/graphql/graphql.github.io/blob/source/src/pages/blog/2016-04-19-mocking.mdx A full example demonstrating a GraphQL schema definition and the corresponding mock server configuration using mockServer and MockList to generate dynamic, realistic data. ```javascript import { mockServer, MockList } from "graphql-tools" import casual from "casual-browserify" const schema = ` type User { id: ID!; name: String; lists: [List] } type List { id: ID!; name: String; owner: User; incomplete_count: Int; tasks(completed: Boolean): [Task] } type Task { id: ID!; text: String; completed: Boolean; list: List } type RootQuery { user(id: ID): User } schema { query: RootQuery } ` const server = mockServer(schema, { RootQuery: () => ({ user: (o, { id }) => ({ id }) }), List: () => ({ name: () => casual.word, tasks: () => new MockList(4, (o, { completed }) => ({ completed })), }), Task: () => ({ text: casual.words(10) }), User: () => ({ name: casual.name }), }) server.query(` query tasksForUser{ user(id: 6) { id name lists { name completeTasks: tasks(completed: true) { completed; text } incompleteTasks: tasks(completed: false) { completed; text } anyTasks: tasks { completed; text } } } }`) ``` -------------------------------- ### Example GraphQL Query Source: https://github.com/graphql/graphql.github.io/blob/source/src/components/code-blocks/schema.mdx An example query to fetch the hero's name and their home world's climate. ```APIDOC ## POST /graphql ### Description This endpoint allows you to execute GraphQL queries against the API to fetch data. ### Method POST ### Endpoint /graphql ### Request Body - **query** (String) - Required - The GraphQL query string. - **variables** (Object) - Optional - Variables to be used in the query. ### Request Example ```json { "query": "query GetHeroHomeWorldClimate {\n hero {\n name\n homeWorld {\n name\n climate\n }\n }\n}" } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the result of the query. - **hero** (Object) - **name** (String) - The name of the hero. - **homeWorld** (Object) - **name** (String) - The name of the hero's home world. - **climate** (String) - The climate of the home world. #### Response Example ```json { "data": { "hero": { "name": "R2-D2", "homeWorld": { "name": "Naboo", "climate": "temperate" } } } } ``` ``` -------------------------------- ### Basic Mocking Source: https://github.com/graphql/graphql.github.io/blob/source/src/pages/blog/2016-04-19-mocking.mdx Demonstrates how to set up a mock server with basic type mocking for Int, Float, and String. ```APIDOC ## Basic Mocking ### Description This example shows how to mock basic scalar types like Int, Float, and String. ### Method N/A (Configuration) ### Endpoint N/A (Configuration) ### Parameters N/A ### Request Example N/A ### Response N/A ```javascript // customize mocking per type (i.e. Integer, Float, String) mockServer(schema, { Int: () => 6, Float: () => 22.1, String: () => 'Hello' }) ``` ``` -------------------------------- ### Run Development Server Source: https://github.com/graphql/graphql.github.io/blob/source/CONTRIBUTING.md Launch the local development server using the `dev` script. Access the site at http://localhost:3000. The site uses Nextra for a hot-reloading development environment. ```sh pnpm dev ``` -------------------------------- ### GraphQL Query Example Source: https://github.com/graphql/graphql.github.io/blob/source/src/pages/learn/execution.mdx This is an example of a GraphQL query requesting human data, including their name, appearing in episodes, and associated starships. ```graphql query { human(id: 1002) { name appearsIn starships { name } } } ``` -------------------------------- ### Basic Setup with ASP.NET Core and EF Core Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/c-net/server/entity-graphql.md This snippet demonstrates how to configure Entity GraphQL in an ASP.NET Core application using Entity Framework Core to automatically build a GraphQL schema from an existing data model. ```APIDOC ## Configure Entity GraphQL with ASP.NET Core and EF Core ### Description This example shows the basic setup for exposing an existing data model as a GraphQL API using Entity GraphQL with ASP.NET Core and Entity Framework Core. It includes configuring services and endpoints. ### Method N/A (Configuration) ### Endpoint N/A (Configuration) ### Parameters N/A ### Request Example N/A ### Response N/A ### Code Example (C#) ```csharp // expose an existing data model with ASP.NET & EF Core public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddDbContext(); // Auto build a schema from DemoContext. Alternatively you can build one from scratch services.AddGraphQLSchema(options => { // modify the schema (add/remove fields or types), add other services }); } public void Configure(IApplicationBuilder app, DemoContext db) { app.UseRouting(); app.UseEndpoints(endpoints => { // defaults to /graphql endpoint endpoints.MapGraphQL(); }); } } ``` ``` -------------------------------- ### Install GraphQLBox Dependencies Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/javascript/client/graphql-box.md Installs the core GraphQLBox packages along with necessary cache management and request parsing modules via npm. ```bash npm install @graphql-box/core @graphql-box/client @graphql-box/request-parser @graphql-box/cache-manager @graphql-box/debug-manager @graphql-box/fetch-manager @graphql-box/helpers @cachemap/core @cachemap/reaper @cachemap/indexed-db @cachemap/constants @cachemap/types ``` -------------------------------- ### GET /graphql Source: https://github.com/graphql/graphql.github.io/blob/source/src/pages/learn/serving-over-http.mdx Executes a GraphQL query operation using the HTTP GET method. This is suitable for caching but limited by URL length constraints. ```APIDOC ## GET /graphql ### Description Executes a GraphQL query operation. Use this for queries only; mutations must use POST. ### Method GET ### Endpoint /graphql ### Parameters #### Query Parameters - **query** (string) - Required - The GraphQL query document string. - **variables** (string) - Optional - A JSON-encoded string of query variables. - **operationName** (string) - Optional - The name of the operation to execute if multiple are provided. ### Request Example GET /graphql?query={me{name}}&variables={"id":1} ### Response #### Success Response (200) - **data** (object) - The result of the GraphQL execution. - **errors** (array) - Optional - List of errors if any occurred. - **extensions** (object) - Optional - Additional metadata. #### Response Example { "data": { "me": { "name": "John Doe" } } } ``` -------------------------------- ### Tartiflette Hello World Example Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/python/server/tartiflette.md A Python script demonstrating a basic GraphQL API with Tartiflette. It defines a 'hello' query and executes it asynchronously. Requires the tartiflette library. ```python import asyncio from tartiflette import Engine, Resolver @Resolver("Query.hello") async def resolver_hello(parent, args, ctx, info): return "hello " + args["name"] async def run(): tftt_engine = Engine(""" type Query { hello(name: String): String } """) result = await tftt_engine.execute( query='query { hello(name: "Chuck") }' ) print(result) # {'data': {'hello': 'hello Chuck'}} if __name__ == "__main__": loop = asyncio.get_event_loop() loop.run_until_complete(run()) ``` -------------------------------- ### Execute Hello World GraphQL Query with graphql-clj Source: https://github.com/graphql/graphql.github.io/blob/source/src/code/language-support/clojure/server/graphql-clj.md This snippet demonstrates how to define a GraphQL schema and execute a simple 'Hello world!' query using the graphql-clj library. It involves setting up the schema, defining a resolver function, and using the executor to process the query. Dependencies include the graphql-clj library itself. ```clojure (def schema "type QueryRoot { hello: String }") (defn resolver-fn [type-name field-name] (get-in {"QueryRoot" {"hello" (fn [context parent & rest] "Hello world!")}}) [type-name field-name])) (require '[graphql-clj.executor :as executor]) (executor/execute nil schema resolver-fn "{ hello }") ```