Skip to content

Implement the Relay Global Object Identification Specification #1585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions features/graphql/collection.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,92 @@
Feature: GraphQL collection support
@createSchema
@dropSchema
Scenario: Retrieve a collection through a GraphQL query
Given there is 4 dummy objects with relatedDummy and its thirdLevel
When I send the following GraphQL request:
"""
{
dummies {
...dummyFields
}
}
fragment dummyFields on DummyConnection {
edges {
node {
id
name
relatedDummy {
name
thirdLevel {
id
level
}
}
}
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.dummies.edges[2].node.name" should be equal to "Dummy #3"
And the JSON node "data.dummies.edges[2].node.relatedDummy.name" should be equal to "RelatedDummy #3"
And the JSON node "data.dummies.edges[2].node.relatedDummy.thirdLevel.level" should be equal to "3"

@createSchema
@dropSchema
Scenario: Retrieve an nonexistent collection through a GraphQL query
When I send the following GraphQL request:
"""
{
dummies {
edges {
node {
name
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.dummies.edges" should have 0 element
And the JSON node "data.dummies.pageInfo.endCursor" should be null
And the JSON node "data.dummies.pageInfo.hasNextPage" should be false

@createSchema
@dropSchema
Scenario: Retrieve a collection with a nested collection through a GraphQL query
Given there is 4 dummy objects having each 3 relatedDummies
When I send the following GraphQL request:
"""
{
dummies {
edges {
node {
name
relatedDummies {
edges {
node {
name
}
}
}
}
}
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.dummies.edges[2].node.name" should be equal to "Dummy #3"
And the JSON node "data.dummies.edges[2].node.relatedDummies.edges[1].node.name" should be equal to "RelatedDummy23"

@createSchema
@dropSchema
Expand Down
85 changes: 85 additions & 0 deletions features/graphql/introspection.feature
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,91 @@ Feature: GraphQL introspection support
And the JSON node "data.type3.fields[1].name" should be equal to "cursor"
And the JSON node "data.type3.fields[0].type.name" should be equal to "DummyAggregateOffer"

Scenario: Retrieve the Relay's node interface
When I send the following GraphQL request:
"""
{
__type(name: "Node") {
name
kind
fields {
name
type {
kind
ofType {
name
kind
}
}
}
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON should be deep equal to:
"""
{
"data": {
"__type": {
"name": "Node",
"kind": "INTERFACE",
"fields": [
{
"name": "id",
"type": {
"kind": "NON_NULL",
"ofType": {
"name": "ID",
"kind": "SCALAR"
}
}
}
]
}
}
}
"""

Scenario: Retrieve the Relay's node field
When I send the following GraphQL request:
"""
{
__schema {
queryType {
fields {
name
type {
name
kind
}
args {
name
type {
kind
ofType {
name
kind
}
}
}
}
}
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.__schema.queryType.fields[0].name" should be equal to "node"
And the JSON node "data.__schema.queryType.fields[0].type.name" should be equal to "Node"
And the JSON node "data.__schema.queryType.fields[0].type.kind" should be equal to "INTERFACE"
And the JSON node "data.__schema.queryType.fields[0].args[0].name" should be equal to "id"
And the JSON node "data.__schema.queryType.fields[0].args[0].type.kind" should be equal to "NON_NULL"
And the JSON node "data.__schema.queryType.fields[0].args[0].type.ofType.name" should be equal to "ID"
And the JSON node "data.__schema.queryType.fields[0].args[0].type.ofType.kind" should be equal to "SCALAR"

@dropSchema
Scenario: Retrieve an item through a GraphQL query
Given there is 4 dummy objects with relatedDummy
Expand Down
136 changes: 37 additions & 99 deletions features/graphql/query.feature
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
Feature: GraphQL query support

@createSchema
@dropSchema
Scenario: Retrieve an item through a GraphQL query with variables
Scenario: Execute a basic GraphQL query
Given there is 2 dummy objects with relatedDummy
When I send the following GraphQL request:
"""
{
dummy(id: "/dummies/1") {
id
name
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.dummy.id" should be equal to "/dummies/1"
And the JSON node "data.dummy.name" should be equal to "Dummy #1"

Scenario: Retrieve a Relay Node
When I send the following GraphQL request:
"""
{
node(id: "/dummies/1") {
id
... on Dummy {
name
}
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.node.id" should be equal to "/dummies/1"
And the JSON node "data.node.name" should be equal to "Dummy #1"

Scenario: Retrieve an item through a GraphQL query with variables
When I have the following GraphQL request:
"""
query DummyWithId($itemId: ID = "/dummies/1") {
Expand All @@ -17,7 +49,7 @@ Feature: GraphQL query support
}
}
"""
When I send the GraphQL request with variables:
And I send the GraphQL request with variables:
"""
{
"itemId": "/dummies/2"
Expand All @@ -31,10 +63,7 @@ Feature: GraphQL query support
And the JSON node "data.dummyItem.relatedDummy.id" should be equal to "/related_dummies/2"
And the JSON node "data.dummyItem.relatedDummy.name" should be equal to "RelatedDummy #2"

@createSchema
@dropSchema
Scenario: Run a specific operation through a GraphQL query
Given there is 2 dummy objects
When I have the following GraphQL request:
"""
query DummyWithId1 {
Expand All @@ -58,14 +87,12 @@ Feature: GraphQL query support
And I send the GraphQL request with operation "DummyWithId1"
And the JSON node "data.dummyItem.name" should be equal to "Dummy #1"

@createSchema
@dropSchema
Scenario: Retrieve an nonexistent item through a GraphQL query
Given there is 1 dummy objects
When I send the following GraphQL request:
"""
{
dummy(id: "/dummies/2") {
dummy(id: "/dummies/5") {
name
}
}
Expand All @@ -74,92 +101,3 @@ Feature: GraphQL query support
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.dummy" should be null

@createSchema
@dropSchema
Scenario: Retrieve a collection through a GraphQL query
Given there is 4 dummy objects with relatedDummy and its thirdLevel
When I send the following GraphQL request:
"""
{
dummies {
...dummyFields
}
}
fragment dummyFields on DummyConnection {
edges {
node {
id
name
relatedDummy {
name
thirdLevel {
id
level
}
}
}
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.dummies.edges[2].node.name" should be equal to "Dummy #3"
And the JSON node "data.dummies.edges[2].node.relatedDummy.name" should be equal to "RelatedDummy #3"
And the JSON node "data.dummies.edges[2].node.relatedDummy.thirdLevel.level" should be equal to "3"

@createSchema
@dropSchema
Scenario: Retrieve an nonexistent collection through a GraphQL query
When I send the following GraphQL request:
"""
{
dummies {
edges {
node {
name
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.dummies.edges" should have 0 element
And the JSON node "data.dummies.pageInfo.endCursor" should be null
And the JSON node "data.dummies.pageInfo.hasNextPage" should be false

@createSchema
@dropSchema
Scenario: Retrieve a collection with a nested collection through a GraphQL query
Given there is 4 dummy objects having each 3 relatedDummies
When I send the following GraphQL request:
"""
{
dummies {
edges {
node {
name
relatedDummies {
edges {
node {
name
}
}
}
}
}
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.dummies.edges[2].node.name" should be equal to "Dummy #3"
And the JSON node "data.dummies.edges[2].node.relatedDummies.edges[1].node.name" should be equal to "RelatedDummy23"
14 changes: 7 additions & 7 deletions src/Bridge/Symfony/Bundle/Resources/config/graphql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<!-- Resolvers -->

<service id="api_platform.graphql.resolver.collection_factory" class="ApiPlatform\Core\Graphql\Resolver\CollectionResolverFactory" public="false">
<service id="api_platform.graphql.resolver.factory.collection" class="ApiPlatform\Core\Graphql\Resolver\Factory\CollectionResolverFactory" public="false">
<argument type="service" id="api_platform.collection_data_provider" />
<argument type="service" id="api_platform.subresource_data_provider" />
<argument type="service" id="serializer" />
Expand All @@ -19,15 +19,15 @@
<argument>%api_platform.collection.pagination.enabled%</argument>
</service>

<service id="api_platform.graphql.resolver.item_factory" class="ApiPlatform\Core\Graphql\Resolver\ItemResolverFactory" public="false">
<service id="api_platform.graphql.resolver.factory.item_mutation" class="ApiPlatform\Core\Graphql\Resolver\Factory\ItemMutationResolverFactory" public="false">
<argument type="service" id="api_platform.iri_converter" />
<argument type="service" id="api_platform.data_persister" />
<argument type="service" id="serializer" />
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
</service>

<service id="api_platform.graphql.resolver.item_mutation_factory" class="ApiPlatform\Core\Graphql\Resolver\ItemMutationResolverFactory" public="false">
<service id="api_platform.graphql.resolver.item" class="ApiPlatform\Core\Graphql\Resolver\ItemResolver" public="false">
<argument type="service" id="api_platform.iri_converter" />
<argument type="service" id="api_platform.data_persister" />
<argument type="service" id="serializer" />
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
</service>
Expand All @@ -41,9 +41,9 @@
<argument type="service" id="api_platform.metadata.property.metadata_factory" />
<argument type="service" id="api_platform.metadata.resource.name_collection_factory" />
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
<argument type="service" id="api_platform.graphql.resolver.collection_factory" />
<argument type="service" id="api_platform.graphql.resolver.item_factory" />
<argument type="service" id="api_platform.graphql.resolver.item_mutation_factory" />
<argument type="service" id="api_platform.graphql.resolver.factory.collection" />
<argument type="service" id="api_platform.graphql.resolver.factory.item_mutation" />
<argument type="service" id="api_platform.graphql.resolver.item" />
<argument type="service" id="api_platform.graphql.resolver.resource_field" />
<argument>%api_platform.collection.pagination.enabled%</argument>
</service>
Expand Down
Loading