Skip to content
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

Pagination: add connectionFields argument to @typePolicy #4265

Merged
merged 13 commits into from
Jul 18, 2022
Merged

Conversation

BoD
Copy link
Contributor

@BoD BoD commented Jul 13, 2022

To simplify the Relay/Connection style pagination, a new connectionsFields argument is added to @typePolicy:

extend type Query
@typePolicy(connectionFields: "sessions, rooms")

# Equivalent to:

extend type Query
@typePolicy(embeddedFields: "sessions, rooms")
@fieldPolicy(forField: "sessions", paginationArgs: "first, after, last, before")
@fieldPolicy(forField: "rooms", paginationArgs: "first, after, last, before")

extend type SessionConnection @typePolicy(embeddedFields: "edges")
extend type RoomConnection @typePolicy(embeddedFields: "edges")

This also generates a new Pagination object with a connectionTypes: Set<String> field, which can be passed to ConnectionMetadataGenerator (now available in apollo-normalized-cache-api-incubating, among with ConnectionMetadataGenerator).

The connectionFields argument must be opted-in by linking (importing) the kotlin_labs v0.2 directives like so:

extend schema @link(url: "https://specs.apollo.dev/kotlin_labs/v0.2", import: ["@typePolicy", "@fieldPolicy"])

See also this PR that adds kotlin_labs v0.2 to the public specs site.

@netlify
Copy link

netlify bot commented Jul 13, 2022

Deploy Preview for apollo-android-docs canceled.

Name Link
🔨 Latest commit 51300ab
🔍 Latest deploy log https://app.netlify.com/sites/apollo-android-docs/deploys/62d53a6bd8d09d0008672094

Copy link
Contributor

@martinbonnin martinbonnin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

}

private val GQLTypeDefinition.directives
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be on GQLTypeDefinition directly instead of an extension?

Copy link
Contributor

@martinbonnin martinbonnin Jul 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going that road, we could add a GQLHasDirectives interface like there is GQLNamed and GQLDescribed. I'm not 100% sure the implications of this though.

BoD added 5 commits July 15, 2022 15:57
…resOptIn, and add it to @typePolicy.connectionFields"

This reverts commit f3a95a3.
…no import is specified).

`connectionFields` is on v0.2 only and made opt-in that way
*/
fun apolloDefinitions() = definitionsFromResources("apollo.graphqls")
fun apolloDefinitions() = apolloDefinitions("v0.1")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make Deprecated?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably make apolloDefinitions(version: String) public if we want to keep offering that possibility. I'd be surprised if anyone is relying on this at the moment but it might be useful for some use cases?

#
# extend schema @link(url: "https://specs.apollo.dev/kotlin_labs/v0.1", import: ["@optional", "@nonnull", "@typePolicy", "@fieldPolicy"])
# extend schema @link(url: "https://specs.apollo.dev/kotlin_labs/v0.1", import: ["@optional", "@nonnull", "@typePolicy", "@fieldPolicy", "requiresOptIn", "targetName"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@BoD BoD merged commit cd71a46 into main Jul 18, 2022
@BoD BoD deleted the pagination-directive branch July 18, 2022 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants