Skip to content

feat(GH-235): added Relay Connection support #236

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
Jan 21, 2020

Conversation

igdianov
Copy link
Collaborator

@igdianov igdianov commented Jan 21, 2020

This adds experimental support for GraphQL Relay Connection wrapper. The Relay can be enabled with enableRelay(true) method on GraphQLJpaSchemaBuilder instance, i.e.

    @Configuration
    public static class GraphQLJpaQuerySchemaConfigurer implements GraphQLSchemaConfigurer {

        private final EntityManager entityManager;

        @Autowired
        private GraphQLJpaQueryProperties properties;

        public GraphQLJpaQuerySchemaConfigurer(EntityManager entityManager) {
            this.entityManager = entityManager;
        }

        @Override
        public void configure(GraphQLShemaRegistration registry) {
            registry.register(
                    new GraphQLJpaSchemaBuilder(entityManager)
                        .name(properties.getName())
                        .description(properties.getDescription())
                        .useDistinctParameter(properties.isUseDistinctParameter())
                        .defaultDistinct(properties.isDefaultDistinct())
                        .enableRelay(properties.isEnableRelay())
                        .build()
            );
        }
    }    

With Relay enabled, it will generate Relay Connection wrappers for plural entity fileds, i.e.

image

After that, it will allow to execute queries using Relay schema with opaque cursors:

query {
  books(
    first: 2
    where: {title: {IS_NULL: false}}
  ) {
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
    edges {
      node {
        id
        title
        genre
        tags
        author {
          id
          name
        }
      }
      cursor
    }
  }
}
{
  "data": {
    "books": {
      "pageInfo": {
        "hasNextPage": true,
        "hasPreviousPage": false,
        "startCursor": "b2Zmc2V0PTE=",
        "endCursor": "b2Zmc2V0PTI="
      },
      "edges": [
        {
          "node": {
            "id": 2,
            "title": "War and Peace",
            "genre": "NOVEL",
            "tags": [
              "piece",
              "war"
            ],
            "author": {
              "id": 1,
              "name": "Leo Tolstoy"
            }
          },
          "cursor": "b2Zmc2V0PTE="
        },
        {
          "node": {
            "id": 3,
            "title": "Anna Karenina",
            "genre": "NOVEL",
            "tags": [
              "karenina",
              "anna"
            ],
            "author": {
              "id": 1,
              "name": "Leo Tolstoy"
            }
          },
          "cursor": "b2Zmc2V0PTI="
        }
      ]
    }
  }
}

Fixes #235

@igdianov igdianov self-assigned this Jan 21, 2020
@codecov
Copy link

codecov bot commented Jan 21, 2020

Codecov Report

Merging #236 into master will decrease coverage by 1.74%.
The diff coverage is 62.14%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #236      +/-   ##
============================================
- Coverage     72.41%   70.67%   -1.75%     
- Complexity      919      934      +15     
============================================
  Files            54       62       +8     
  Lines          4180     4351     +171     
  Branches        644      661      +17     
============================================
+ Hits           3027     3075      +48     
- Misses          873      998     +125     
+ Partials        280      278       -2
Impacted Files Coverage Δ Complexity Δ
...phql/jpa/query/schema/relay/OffsetBasedCursor.java 0% <0%> (ø) 0 <0> (?)
...es/graphql/jpa/query/schema/relay/GenericPage.java 0% <0%> (ø) 0 <0> (?)
...query/schema/relay/GraphQLJpaRelayDataFetcher.java 0% <0%> (ø) 0 <0> (?)
...ures/graphql/jpa/query/schema/relay/SortField.java 0% <0%> (ø) 0 <0> (?)
...es/graphql/jpa/query/schema/relay/PageFactory.java 0% <0%> (ø) 0 <0> (?)
...raphql/jpa/query/schema/relay/PagingArguments.java 0% <0%> (ø) 0 <0> (?)
...query/schema/impl/GraphQLJpaStreamDataFetcher.java 100% <100%> (+19.51%) 4 <0> (ø) ⬇️
...es/graphql/jpa/query/schema/impl/PageArgument.java 100% <100%> (ø) 4 <4> (?)
.../query/schema/impl/GraphQLJpaQueryDataFetcher.java 91.66% <100%> (+1.14%) 7 <4> (-12) ⬇️
...query/schema/impl/GraphQLJpaSimpleDataFetcher.java 92.3% <100%> (+1.13%) 5 <0> (-6) ⬇️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3db0e51...17fdfa2. Read the comment docs.

@igdianov igdianov merged commit 36703f0 into master Jan 21, 2020
@igdianov igdianov deleted the feat-GH-235-relay-connection branch January 21, 2020 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Support fo Relay Cursor Connections
1 participant