Last active
April 7, 2018 08:40
-
-
Save crisu83/e7db29b7238d483dbc13f7c085d20658 to your computer and use it in GitHub Desktop.
Type resolver concept for https://github.com/digiaonline/graphql-php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Vehicle { | |
maxSpeed: Int | |
} | |
type Airplane implements Vehicle { | |
maxSpeed: Int | |
wingspan: Int | |
} | |
type Car implements Vehicle { | |
maxSpeed: Int | |
licensePlate: String | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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