GraphQL

phpnomad/graphql is PHPNomad's abstract GraphQL layer. It defines the contracts for building a GraphQL API — type definitions, field resolvers, execution, and schema composition — in a way that's agnostic to any particular GraphQL engine.

The package contains only interfaces and a small exception class. Concrete execution is provided by a separate integration package (e.g. phpnomad/webonyx-integration). This separation means you can swap engines without touching your type definitions or resolvers.

Key ideas at a glance


The Execution Flow

When a GraphQL query enters a system wired with phpnomad/graphql:

Request → GraphQLStrategy::execute() → Schema (built from TypeDefinitions) → FieldResolvers → array result

TypeDefinitions registered at boot

During application boot, initializers implementing HasTypeDefinitions push SDL + resolver maps into the GraphQLStrategy. The strategy accumulates these and builds the final schema lazily on first execution.

execute()

GraphQLStrategy::execute() accepts a query string, a variables map, and a ResolverContext. It returns a plain PHP array matching the GraphQL wire format (['data' => [...]] or ['errors' => [...]]).

FieldResolvers

For each field that has custom logic, a FieldResolver class is registered in the TypeDefinition's resolver map. The strategy resolves these from the DI container at query time. Fields with no entry use the engine's default property resolution (reading $rootValue['fieldName'] or $rootValue->fieldName).


Packages

Package Purpose
phpnomad/graphql Interfaces only — portable, no engine dependency
phpnomad/webonyx-integration Concrete engine using webonyx/graphql-php

Installation

composer require phpnomad/graphql

For the concrete engine:

composer require phpnomad/webonyx-integration