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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for entities without a reference resolver #1378

Merged
merged 2 commits into from
Sep 23, 2023

Conversation

akrantz01
Copy link
Contributor

Resolves #1361

Heya 馃憢

This PR adds support for defining entities without a reference resolver using the resolvable parameter of the @key directive on the SimpleObject and Object macros.

The key to be marked unresolvable can be either implicitly (#[graphql(unresolvable)]) or explicitly (#[graphql(unresolvable = "<key>")]) defined. When implicitly defined, the macro assumes all non-skipped fields are part of the key. When explicitly defined, the macro assumes the provided key is valid for the object. The explicit key will most likely be used for entities referenced by compound keys with nested fields, which cannot be easily validated.

This should not be a breaking change. The resolvable argument defaults to true, so it will not affect schema generation unless explicitly requested.

Example usage:

#[derive(SimpleObject)]
#[graphql(unresolvable)] // <-- new attribute
struct ImplicitObject {
	pub id: u64,
	pub username: String,
}

#[derive(SimpleObject)]
#[graphql(unresolvable = "id")] // <-- new attribute
struct ExplicitObject {
    pub id: u64,
}

This example will generate the following schema:

#                                               v-- added directive argument
type ImplicitObject @key(fields: "id username", resolvable: false) {
    id: Int!
    username: String!
}

#                                      v-- added directive argument
type ExplicitObject @key(fields: "id", resolvable: false) {
    id: Int!
}

These objects will also not be added to the _Entity union as they cannot be resolved by the subgraph.

@sunli829
Copy link
Collaborator

thanks! 馃檪

@sunli829 sunli829 merged commit 3626cfa into async-graphql:master Sep 23, 2023
8 checks passed
@akrantz01 akrantz01 deleted the key-directive-resolvable branch September 23, 2023 03:29
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.

None yet

2 participants