Skip to content

Instantly share code, notes, and snippets.

@SerafimArts
Created July 21, 2017 15:54
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 SerafimArts/e4bf567a305a13bf58569b7062cf0ebf to your computer and use it in GitHub Desktop.
Save SerafimArts/e4bf567a305a13bf58569b7062cf0ebf to your computer and use it in GitHub Desktop.
GraphQL IDL reader based on Yay PHP
type Story implements Test {
id: ID! @test(some: "any")
text: String!
isPublished: Boolean
author: Author!
comments: [Comment!]!
}
type Author {
id: ID!
}
macro ·global ·unsafe {
type T_STRING·typeName ·optional(
·chain(
·token(T_IMPLEMENTS),
·lst(T_STRING·interfaceName, ·token(','))·interfaces
)·interfacesDefinition
) {
·optional(
·lst(
·chain(
T_STRING·field,
·token(':'),
·chain(
·either(
·token(T_STRING),
·chain(
·token('['),
·token(T_STRING),
·optional(·token('!')),
·token(']')
)
),
·optional(·token('!'))
)·fieldType
),
·optional(
·ls(
·chain(
·token('@'),
T_STRING·directiveName,
·optional(
·chain(
·token('('),
·optional(
·lst(
·chain(
T_STRING·directiveArgument,
·token(':'),
·either(
·label(),
·token(T_DNUMBER),
·token(T_LNUMBER),
·token(T_NUM_STRING),
·token(T_ENCAPSED_AND_WHITESPACE),
·token(T_CONSTANT_ENCAPSED_STRING)
)·directiveValue
),
·token(',')
)·directiveArguments
),
·token(')')
)
)
),
·optional(·token(T_WHITESPACE))
)·directive
),
·token(',')
)·fields
)
}
} >> {
$this->registerObject([
'name' => ··stringify(T_STRING·typeName),
'fields' => [
·fields ··· {
··stringify(T_STRING·field) => [
'type' => $this->type(··stringify(·fieldType)),
],
}
],
·interfacesDefinition ··· {
'interfaces' => [
·interfaces ··· {
$this->type(··stringify(T_STRING·interfaceName)),
}
],
}
]);
}
<?php
$this->registerObject([
'name' => 'Story',
'fields' => [
'id' => [
'type' => $this->type('ID!'),
],
'text' => [
'type' => $this->type('String!'),
],
'isPublished' => [
'type' => $this->type('Boolean'),
],
'author' => [
'type' => $this->type('Author!'),
],
'comments' => [
'type' => $this->type('[Comment!]!'),
],
],
'interfaces' => [
$this->type('Test'),
],
]);
$this->registerObject([
'name' => 'Author',
'fields' => [
'id' => [
'type' => $this->type('ID!'),
],
],
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment