Skip to content

Instantly share code, notes, and snippets.

@crisu83
Last active April 7, 2018 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crisu83/e7db29b7238d483dbc13f7c085d20658 to your computer and use it in GitHub Desktop.
Save crisu83/e7db29b7238d483dbc13f7c085d20658 to your computer and use it in GitHub Desktop.
Type resolver concept for https://github.com/digiaonline/graphql-php
interface Vehicle {
maxSpeed: Int
}
type Airplane implements Vehicle {
maxSpeed: Int
wingspan: Int
}
type Car implements Vehicle {
maxSpeed: Int
licensePlate: String
}
class VehicleResolver extends AbstractResolver
{
public function resolveFoo()
{
return 'foo';
}
public function resolveType($rootValue, $contextValues, $info)
{
if ($rootValue instanceof Airplane) {
return 'Airplane';
}
if ($rootValue instanceof Car) {
return 'Car';
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment