### PHP GraphQL Server Setup Source: https://github.com/webonyx/graphql-php/blob/master/examples/05-type-config-decorator/README.md Instructions for setting up a local PHP development server to run the GraphQL example. This involves installing dependencies and starting the server. ```bash composer install php -S localhost:8080 graphql.php ``` -------------------------------- ### Project Setup Source: https://github.com/webonyx/graphql-php/blob/master/CONTRIBUTING.md Steps to clone the repository, navigate into the project directory, and install dependencies using Composer. ```sh git clone cd graphql-php composer install ``` -------------------------------- ### Install ReactPHP Dependencies Source: https://github.com/webonyx/graphql-php/blob/master/examples/04-async-php/reactphp/hello-world-http-server/README.md Installs the required ReactPHP libraries for asynchronous operations in your project using Composer. ```bash composer require react/promise react/http ``` -------------------------------- ### Run Local Test Server Source: https://github.com/webonyx/graphql-php/blob/master/examples/03-standard-server/README.md Starts a local PHP development server on port 8080 to serve the GraphQL endpoint. ```bash php -S localhost:8080 graphql.php ``` -------------------------------- ### Run Local Test Server Source: https://github.com/webonyx/graphql-php/blob/master/examples/01-blog/README.md Starts a local PHP development server to host the GraphQL API on localhost:8080. ```sh php -S localhost:8080 graphql.php ``` -------------------------------- ### Run GraphQL Server and Test Query Source: https://github.com/webonyx/graphql-php/blob/master/docs/getting-started.md Starts a local PHP development server and sends a sample GraphQL query using curl to test the 'Hello World' example. ```sh php -S localhost:8080 graphql.php curl http://localhost:8080 -d '{"query": "query { echo(message: \"Hello World\") }" }' ``` -------------------------------- ### Run Local Test Server Source: https://github.com/webonyx/graphql-php/blob/master/examples/00-hello-world/README.md Starts a local PHP development server on port 8080 to serve the GraphQL endpoint. ```bash php -S localhost:8080 graphql.php ``` -------------------------------- ### Install AMPHP HTTP Server Dependency Source: https://github.com/webonyx/graphql-php/blob/master/examples/04-async-php/amphp/http-server/README.md This snippet shows the Composer command to install the AMPHP HTTP server dependency required for the example. ```bash composer require amphp/http-server ``` -------------------------------- ### Run GraphQL PHP Example Source: https://github.com/webonyx/graphql-php/blob/master/examples/04-async-php/reactphp/hello-world-http-server/README.md Executes the GraphQL PHP example script locally using the PHP built-in web server. ```bash php graphql.php ``` -------------------------------- ### Run Local Test Server Source: https://github.com/webonyx/graphql-php/blob/master/examples/02-schema-definition-language/README.md Starts a local PHP development server on port 8080 to host the GraphQL endpoint. ```bash php -S localhost:8080 graphql.php ``` -------------------------------- ### Install graphql-php with Composer Source: https://github.com/webonyx/graphql-php/blob/master/docs/getting-started.md Installs the graphql-php library using Composer, the dependency manager for PHP. ```sh composer require webonyx/graphql-php ``` -------------------------------- ### Test GraphQL Query Source: https://github.com/webonyx/graphql-php/blob/master/examples/00-hello-world/README.md Sends a sample 'Hello World' query to the local GraphQL server using curl. ```bash curl --data '{"query": "query { echo(message: \"Hello World\") }" }' --header "Content-Type: application/json" http://localhost:8080 ``` -------------------------------- ### Run Local HTTP Server Source: https://github.com/webonyx/graphql-php/blob/master/examples/04-async-php/amphp/http-server/README.md This snippet provides the command to execute the GraphQL PHP script and start the local HTTP server. ```bash php graphql.php ``` -------------------------------- ### GraphQL\Server\StandardServer Basic Usage Example Source: https://github.com/webonyx/graphql-php/blob/master/docs/class-reference.md This example demonstrates the basic instantiation and usage of the `StandardServer` class. It shows how to create a server instance by directly passing a schema and then handling an incoming GraphQL request. ```php $server = new StandardServer([ 'schema' => $mySchema ]); $server->handleRequest(); ``` -------------------------------- ### Install graphql-php via Composer Source: https://github.com/webonyx/graphql-php/blob/master/README.md This command installs the graphql-php package using Composer, the dependency manager for PHP. Ensure Composer is installed and accessible in your environment. ```sh composer require webonyx/graphql-php ``` -------------------------------- ### Example GraphQL Query Source: https://github.com/webonyx/graphql-php/blob/master/examples/01-blog/README.md A comprehensive GraphQL query demonstrating fetching viewer details, specific users, stories with comments, and story author information including liked status and formatted body. ```graphql { viewer { id email } user(id: "2") { id email } stories(after: "1") { id body comments { ...CommentView } } lastStoryPosted { id hasViewerLiked author { id photo(size: ICON) { id url size width height # Uncomment following line to see validation error: # nonExistingField # Uncomment to see error reporting for fields with exceptions thrown in resolvers # fieldWithError # nonNullFieldWithError } lastStoryPosted { id } } body(format: HTML, maxLength: 10) } } fragment CommentView on Comment { id body totalReplyCount replies { id body } } ``` -------------------------------- ### GraphQL Query Example Source: https://github.com/webonyx/graphql-php/blob/master/examples/05-type-config-decorator/README.md Example of a GraphQL query to fetch track data, including title, thumbnail, and author details (ID and name). This demonstrates how to structure a query against the defined schema. ```graphql { tracksForHome { title thumbnail author { id name } } } ``` -------------------------------- ### Test GraphQL Mutation Source: https://github.com/webonyx/graphql-php/blob/master/examples/00-hello-world/README.md Sends a sample mutation to the local GraphQL server using curl to test addition. ```bash curl --data '{"query": "mutation { sum(x: 2, y: 2) }" }' --header "Content-Type: application/json" http://localhost:8080 ``` -------------------------------- ### AST DocumentNode Initialization (After) Source: https://github.com/webonyx/graphql-php/blob/master/UPGRADE.md Shows the current method of initializing `DocumentNode`, which now uses `NodeList` for its definitions. ```php use GraphQL\Language\AST\DocumentNode; use GraphQL\Language\NodeList; // Initialize DocumentNode with a NodeList of definitions new DocumentNode([ 'definitions' => new NodeList([/*...*/]) ]); ``` -------------------------------- ### Execute GraphQL Query Source: https://github.com/webonyx/graphql-php/blob/master/examples/03-standard-server/README.md Sends a GraphQL query to the local test server using cURL to test the 'echo' field. ```http curl --data '{"query": "query { echo(message: \"Hello World\") }" }' --header "Content-Type: application/json" http://localhost:8080 ``` -------------------------------- ### AST DocumentNode Initialization (Before) Source: https://github.com/webonyx/graphql-php/blob/master/UPGRADE.md Illustrates the previous way of initializing `DocumentNode` with an array for its definitions. ```php use GraphQL\Language\AST\DocumentNode; // Initialize DocumentNode with an array of definitions new DocumentNode([ 'definitions' => array(/*...*/) ]); ``` -------------------------------- ### Example GraphQL Query Batching Request Body Source: https://github.com/webonyx/graphql-php/blob/master/docs/executing-queries.md Provides an example JSON request body for Apollo-style query batching, illustrating how multiple GraphQL queries can be sent in a single request to potentially reduce database calls if resolvers are deferred. ```json [ { "query": "{user(id: 1) { id }}" }, { "query": "{user(id: 2) { id }}" }, { "query": "{user(id: 3) { id }}" } ] ``` -------------------------------- ### Execute GraphQL Mutation Source: https://github.com/webonyx/graphql-php/blob/master/examples/03-standard-server/README.md Sends a GraphQL mutation to the local test server using cURL to test the 'sum' field. ```http curl --data '{"query": "mutation { sum(x: 2, y: 2) }" }' --header "Content-Type: application/json" http://localhost:8080 ``` -------------------------------- ### Basic Query with Curl Source: https://github.com/webonyx/graphql-php/blob/master/examples/01-blog/README.md Sends a simple GraphQL query to the local test server to verify the endpoint is ready. ```sh curl --data '{"query": "query { hello }" }' --header "Content-Type: application/json" http://localhost:8080 ``` -------------------------------- ### GraphQL Query Example Source: https://github.com/webonyx/graphql-php/blob/master/docs/data-fetching.md An example of a GraphQL query to fetch the last story and its author's name. ```graphql { lastStory { title author { name } } } ``` -------------------------------- ### GraphQL Query Example Source: https://github.com/webonyx/graphql-php/blob/master/docs/concepts.md Demonstrates a basic GraphQL query structure to fetch nested data, mirroring the expected JSON response format. ```graphql { hero { name friends { name } } } ``` ```json { "hero": { "name": "R2-D2", "friends": [ { "name": "Luke Skywalker" }, { "name": "Han Solo" }, { "name": "Leia Organa" } ] } } ``` -------------------------------- ### GraphQL\Server\StandardServer Usage with ServerConfig Source: https://github.com/webonyx/graphql-php/blob/master/docs/class-reference.md This example illustrates a more structured approach to configuring `StandardServer` using a `ServerConfig` instance. It demonstrates setting the schema and context via the `ServerConfig` object before passing it to the `StandardServer` constructor. ```php $config = GraphQL\Server\ServerConfig::create() ->setSchema($mySchema) ->setContext($myContext); $server = new GraphQL\Server\StandardServer($config); $server->handleRequest(); ``` -------------------------------- ### Using Nowdoc Syntax for Tests Source: https://github.com/webonyx/graphql-php/blob/master/CONTRIBUTING.md Example demonstrating the use of PHP's nowdoc syntax for multiline strings in tests, similar to the dedent utility in graphql-js. ```php self::assertSomePrintedOutputExactlyMatches( <<<'GRAPHQL' type Foo { bar: Baz } GRAPHQL, $output ); ``` -------------------------------- ### Reverting to Old Error Formatting (Deprecated) Source: https://github.com/webonyx/graphql-php/blob/master/UPGRADE.md Provides an example of how to temporarily revert to the previous error formatting behavior, which is deprecated and will be removed in future versions. It's recommended to use custom error formatters instead. ```php use GraphQL\GraphQL; // Execute query and use the deprecated default error formatter $result = GraphQL::executeAndReturnResult(/*args*/) ->setErrorFormatter('\GraphQL\Error\Error::formatError') ->toArray(); ``` -------------------------------- ### Standard Server Basic Usage Source: https://github.com/webonyx/graphql-php/blob/master/docs/executing-queries.md Demonstrates the basic initialization and request handling for the GraphQL PHP Standard Server using plain PHP. ```php use GraphQL\Server\StandardServer; $server = new StandardServer([/* server options, see below */]); $server->handleRequest(); // parses PHP globals and emits response ``` -------------------------------- ### Initialize GraphQL\Server\StandardServer Source: https://github.com/webonyx/graphql-php/blob/master/docs/class-reference.md Initializes a new instance of `StandardServer`. The constructor accepts a configuration object or an array of configuration options to set up the server's behavior. ```APIDOC GraphQL\Server\StandardServer::__construct(config: ServerConfig|array) config: ServerConfig|array - The server configuration, either a ServerConfig instance or an associative array. Throws: InvariantViolation ``` -------------------------------- ### Run PHP Server and Test GraphQL Endpoint with cURL Source: https://github.com/webonyx/graphql-php/blob/master/docs/getting-started.md Commands to start a local PHP development server to host the `graphql.php` endpoint and then use `curl` to send a POST request with a GraphQL query to test the 'echo' functionality, demonstrating how to interact with the API. ```sh php -S localhost:8080 graphql.php curl http://localhost:8080 -d '{"query": "query { echo(message: \"Hello World\") }" }' ``` -------------------------------- ### GraphQL Query Example for Enum Input Source: https://github.com/webonyx/graphql-php/blob/master/docs/type-definitions/enums.md An example GraphQL query demonstrating how to pass enum values as arguments to a field. ```graphql fragment on Hero { appearsInNewHope: appearsIn(NEWHOPE) appearsInEmpire: appearsIn(EMPIRE) } ``` -------------------------------- ### GraphQL Schema Definition Example Source: https://github.com/webonyx/graphql-php/blob/master/docs/schema-definition-language.md An example of a GraphQL schema defined in a .graphql file, including a Query type and an input type. ```graphql type Query { greetings(input: HelloInput!): String! } input HelloInput { firstName: String! lastName: String } ``` -------------------------------- ### GraphQL Query Best Practice Example Source: https://github.com/webonyx/graphql-php/blob/master/examples/01-blog/README.md Illustrates an invalid GraphQL query that violates the rule requiring at least one field per object type to prevent over-fetching. ```graphql { viewer } ``` -------------------------------- ### Schema Definition Language (SDL) Example Source: https://github.com/webonyx/graphql-php/blob/master/docs/type-definitions/index.md An example of defining a GraphQL schema using the Schema Definition Language (SDL), including a schema, a query type, and an input type. ```graphql schema { query: Query mutation: Mutation } type Query { greetings(input: HelloInput!): String! } input HelloInput { firstName: String! lastName: String } ``` -------------------------------- ### GraphQL Server Configuration Options Source: https://github.com/webonyx/graphql-php/blob/master/docs/executing-queries.md API documentation for the 'promiseAdapter' configuration option, which is required for Async PHP operations within the GraphQL server. ```APIDOC promiseAdapter: Type: GraphQL\Executor\Promise\PromiseAdapter Description: Required for Async PHP only. ``` -------------------------------- ### Example HTTP POST Request for GraphQL Mutation Source: https://github.com/webonyx/graphql-php/blob/master/docs/concepts.md This JSON example shows how a GraphQL mutation, including its variables, is typically sent as the body of an HTTP POST request to a GraphQL endpoint. The 'query' field contains the mutation string, and 'variables' holds the input data. ```json // POST /graphql-endpoint // Content-Type: application/javascript // { "query": "mutation CreateReviewForEpisode...", "variables": { "ep": "JEDI", "review": { "stars": 5, "commentary": "This is a great movie!" } } } ``` -------------------------------- ### Multiline Ternary Expression Formatting Source: https://github.com/webonyx/graphql-php/blob/master/CONTRIBUTING.md Example illustrating the required formatting for multiline ternary expressions in the project. ```php $foo = $cond ? 1 : 2; ``` -------------------------------- ### Configure GraphQL Server with ServerConfig Class Source: https://github.com/webonyx/graphql-php/blob/master/docs/executing-queries.md Demonstrates how to configure the GraphQL server using the `GraphQL\Server\ServerConfig` class for a fluid interface, providing IDE autocomplete and static time validation, as an alternative to using a plain array. ```php use GraphQL\Server\ServerConfig; use GraphQL\Server\StandardServer; $config = ServerConfig::create() ->setSchema($schema) ->setErrorFormatter($myFormatter) ->setDebugFlag($debug) ; $server = new StandardServer($config); ``` -------------------------------- ### Running Benchmarks Source: https://github.com/webonyx/graphql-php/blob/master/CONTRIBUTING.md Command to execute performance benchmarks using PHPBench. ```sh composer bench ``` -------------------------------- ### GraphQL Validation Configuration Source: https://github.com/webonyx/graphql-php/blob/master/UPGRADE.md Replaces the deprecated `GraphQL\Type\Definition\Config::enableValidation()` with `$schema->assertValid()` for schema validation. ```php $schema->assertValid(); ``` -------------------------------- ### StandardServer Constructor Source: https://github.com/webonyx/graphql-php/blob/master/docs/class-reference.md Initializes the StandardServer with a given configuration. The configuration can be provided as a ServerConfig object or an array of options. ```php /** * @param ServerConfig|array $config * * @api * * @throws InvariantViolation */ function __construct($config) ``` -------------------------------- ### GraphQL Server Configuration Methods Source: https://github.com/webonyx/graphql-php/blob/master/docs/class-reference.md Provides methods to configure the GraphQL server instance. These include setting context, root value, error formatting, error handling, validation rules, persisted query loading, debug flags, and query batching. ```APIDOC GraphQL\Server\ServerConfig: create(array $config = []): self Converts an array of options to instance of ServerConfig (or just returns empty config when array is not passed). Parameters: - config: An array of configuration options. Returns: A new ServerConfig instance. Throws: InvariantViolation setContext(mixed|callable $context): self Sets the context for the GraphQL execution. Parameters: - context: The context value or a callable that resolves the context. Returns: The current ServerConfig instance for chaining. setRootValue(mixed|RootValueResolver $rootValue): self Sets the root value for the GraphQL execution. Parameters: - rootValue: The root value or a RootValueResolver. Returns: The current ServerConfig instance for chaining. setErrorFormatter(callable $errorFormatter): self Sets a custom error formatter for GraphQL errors. Parameters: - errorFormatter: A callable that formats errors. Returns: The current ServerConfig instance for chaining. setErrorsHandler(callable $handler): self Sets a custom handler for GraphQL errors. Parameters: - handler: A callable that handles errors. Returns: The current ServerConfig instance for chaining. setValidationRules(array|callable|null $validationRules): self Sets validation rules for the GraphQL server. Parameters: - validationRules: An array of ValidationRule, a callable, or null. Returns: The current ServerConfig instance for chaining. setPersistedQueryLoader(?callable $persistedQueryLoader): self Sets a loader for persisted queries. Parameters: - persistedQueryLoader: A callable that loads persisted queries or null. Returns: The current ServerConfig instance for chaining. setDebugFlag(int $debugFlag = 'GraphQL\Error\DebugFlag::INCLUDE_DEBUG_MESSAGE'): self Sets response debug flags. Parameters: - debugFlag: An integer representing debug flags. See \GraphQL\Error\DebugFlag for available flags. Returns: The current ServerConfig instance for chaining. setQueryBatching(bool $enableBatching): self Enables or disables query batching. Parameters: - enableBatching: A boolean to enable or disable batching. Returns: The current ServerConfig instance for chaining. ``` -------------------------------- ### Execute GraphQL Query Source: https://github.com/webonyx/graphql-php/blob/master/examples/02-schema-definition-language/README.md Sends a GraphQL query to the local server using cURL to retrieve a message. ```http curl --data '{"query": "query { echo(message: \"Hello World\") }" }' --header "Content-Type: application/json" http://localhost:8080 ``` -------------------------------- ### Async Platform Usage with GraphQL Source: https://github.com/webonyx/graphql-php/blob/master/UPGRADE.md Explains the usage of `GraphQL::promiseToExecute()` for async platforms, which requires a promise adapter and returns a `Promise`. Deprecates `GraphQL::execute` and `Executor::execute` for async operations. ```php GraphQL::promiseToExecute( $promiseAdapter, $schema, $query, $rootValue, $variables, $operationName ); ``` ```php Executor::promiseToExecute( $promiseAdapter, $schema, $query, $rootValue, $variables, $operationName ); ``` -------------------------------- ### Generating Class Reference Documentation Source: https://github.com/webonyx/graphql-php/blob/master/CONTRIBUTING.md Command to generate the class reference documentation using MkDocs. ```sh composer docs ``` -------------------------------- ### GraphQL Response Example for Enum Input Source: https://github.com/webonyx/graphql-php/blob/master/docs/type-definitions/enums.md The expected PHP array output from a GraphQL query that uses enum arguments. ```php [ 'appearsInNewHope' => false, 'appearsInEmpire' => true ] ``` -------------------------------- ### Execute GraphQL Mutation Source: https://github.com/webonyx/graphql-php/blob/master/examples/02-schema-definition-language/README.md Sends a GraphQL mutation to the local server using cURL to perform a sum operation. ```http curl --data '{"query": "mutation { sum(x: 2, y: 2) }" }' --header "Content-Type: application/json" http://localhost:8080 ``` -------------------------------- ### GraphQL Server Configuration with ServerConfig Source: https://github.com/webonyx/graphql-php/blob/master/docs/executing-queries.md Demonstrates how to use the GraphQL\Server\ServerConfig class for fluent interface configuration of the GraphQL server, including setting the schema and error formatter. ```php use GraphQL\Server\ServerConfig; use GraphQL\Server\StandardServer; $config = ServerConfig::create() ->setSchema($schema) ->setErrorFormatter($myFormatter) ->setDebugFlag($debug) ; $server = new StandardServer($config); ``` -------------------------------- ### GraphQL Schema Usage Example Source: https://github.com/webonyx/graphql-php/blob/master/docs/class-reference.md Demonstrates how to create a GraphQL Schema instance in PHP, either by passing an options array directly or by using a SchemaConfig object to configure the root operation types. ```php $schema = new GraphQL\Type\Schema([ 'query' => $MyAppQueryRootType, 'mutation' => $MyAppMutationRootType, ]); ``` ```php $config = GraphQL\Type\SchemaConfig::create() ->setQuery($MyAppQueryRootType) ->setMutation($MyAppMutationRootType); $schema = new GraphQL\Type\Schema($config); ``` -------------------------------- ### GraphQL\Utils Moved to GraphQL\Utils\Utils Source: https://github.com/webonyx/graphql-php/blob/master/UPGRADE.md Indicates that the `GraphQLUtils` class has been moved to `GraphQLUtilsUtils`. Referencing the old location will trigger a deprecation warning. ```php use GraphQL\Utils as OldUtils; use GraphQL\Utils\Utils as NewUtils; // Old location (deprecated) $utilOld = OldUtils::someMethod(); // New location $utilNew = NewUtils::someMethod(); ``` -------------------------------- ### GraphQL Server Configuration Options Source: https://github.com/webonyx/graphql-php/blob/master/docs/executing-queries.md Configuration options for the GraphQL server. These parameters define how the GraphQL execution engine interacts with your application's data and schema. ```APIDOC Server Configuration Options: schema: Schema - Required. Instance of your application Schema. - Reference: [Schema](class-reference.md#graphqltypeschema), [Schema Definition](schema-definition.md) rootValue: mixed - Any value that represents a root of your data graph. - Passed as the 1st argument to field resolvers of Query type. - Can be omitted or set to null if actual root values are fetched by Query type itself. - Reference: [Query and Mutation Types](schema-definition.md#query-and-mutation-types) context: mixed - Any value that holds information shared between all field resolvers. - Often used to pass logged-in user, locale details, etc. - Available as the 3rd argument in all field resolvers. - Reference: [Field Definitions](type-definitions/object-types.md#field-configuration-options) - graphql-php passes this value as-is to all underlying resolvers. fieldResolver: callable - A resolver function to use when one is not provided by the schema. - If not provided, the [default field resolver is used](data-fetching.md#default-field-resolver). ``` -------------------------------- ### GraphQL PHP ClientAware Exception Example Source: https://github.com/webonyx/graphql-php/blob/master/docs/error-handling.md Demonstrates how to create a custom exception that implements the ClientAware interface to safely expose error messages to clients. ```php use GraphQL\Error\ClientAware; class MySafeException extends \Exception implements ClientAware { public function isClientSafe(): bool { return true; } } ``` -------------------------------- ### GraphQL-PHP Configuration Options Source: https://github.com/webonyx/graphql-php/blob/master/docs/executing-queries.md Details the various configuration options available for the graphql-php server, including validation rules, query batching, debugging flags, persisted query loading, and custom error handling. ```APIDOC validationRules: type: `array` or `callable` description: A set of rules for query validation step. The default value is all available rules. The empty array would allow skipping query validation (may be convenient for persisted queries which are validated before persisting and assumed valid during execution). callable signature: function ([OperationParams](class-reference.md#graphqlserveroperationparams) $params, DocumentNode $node, $operationType): array queryBatching: type: `bool` description: Flag indicating whether this server supports query batching ([apollo-style](https://www.apollographql.com/blog/apollo-client/performance/query-batching/)). Defaults to false. debugFlag: type: `int` description: Debug flags. See [docs on error debugging](error-handling.md#debugging-tools). persistedQueryLoader: type: `callable` description: A function which is called to fetch actual query when server encounters a queryId. The server does not implement persistence part, but it allows you to execute queries which were persisted previously. expected signature: function ($queryId, [OperationParams](class-reference.md#graphqlserveroperationparams) $params) returns: query string or parsed DocumentNode more info: [Read more about persisted queries](https://www.apollographql.com/blog/apollo-client/persisted-graphql-queries). errorFormatter: type: `callable` description: Custom error formatter. See [error handling docs](error-handling.md#custom-error-handling-and-formatting). errorsHandler: type: `callable` description: Custom errors handler. See [error handling docs](error-handling.md#custom-error-handling-and-formatting). ``` -------------------------------- ### Running Static Analysis Source: https://github.com/webonyx/graphql-php/blob/master/CONTRIBUTING.md Command to run static analysis checks using PHPStan. ```sh composer stan ``` -------------------------------- ### GraphQL\Schema Moved to GraphQL\Type\Schema Source: https://github.com/webonyx/graphql-php/blob/master/UPGRADE.md Notes the relocation of the `GraphQLSchema` class to `GraphQLTypeSchema`. The old location is still available but will trigger a deprecation warning. ```php use GraphQL\Schema as OldSchema; use GraphQL\Type\Schema as NewSchema; // Old location (deprecated) $schemaOld = new OldSchema(/*...*/); // New location $schemaNew = new NewSchema(/*...*/); ``` -------------------------------- ### Standard Server PSR-7 Integration Source: https://github.com/webonyx/graphql-php/blob/master/docs/executing-queries.md Shows how to integrate the GraphQL PHP Standard Server with PSR-7 request and response interfaces for use within frameworks. ```php use GraphQL\Server\StandardServer; use GraphQL\Executor\ExecutionResult; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; /** @var RequestInterface $psrRequest */ /** @var ResponseInterface $psrResponse */ /** @var StreamInterface $psrBodyStream */ $server = new StandardServer([/* server options, see below */]); $psrResponse = $server->processPsrRequest($psrRequest, $psrResponse, $psrBodyStream); ``` ```php /** @var ExecutionResult|ExecutionResult[] $result */ $result = $server->executePsrRequest($psrRequest); $jsonResult = json_encode($result, JSON_THROW_ON_ERROR); $psrResponse = new SomePsr7ResponseImplementation($jsonResult ); ``` -------------------------------- ### Curl Request for GraphQL Query Source: https://github.com/webonyx/graphql-php/blob/master/examples/05-type-config-decorator/README.md Demonstrates how to send a GraphQL query to a local server using `curl`. This includes setting the content type and providing the query in the request body. ```bash curl --data '{"query": "{ tracksForHome { title thumbnail author { id name } } }"}' --header "Content-Type: application/json" http://localhost:8080 ```