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

Feat(GraphQL): This PR allows @id field in interface to be unique across all implementing types #8876

Merged
merged 2 commits into from
Jul 17, 2023

Conversation

harshil-goel
Copy link
Contributor

@harshil-goel harshil-goel commented Jun 14, 2023

Currently, @id fields in the interface are unique only in one implementing type. But there are several use cases that require @id field to be unique across all the implementation types. Also currently. get a query on the interface can result in unexpected errors as we can have multiple implementing types have the same value for that @id field.

Now we are allowing the @id field in the interface to be unique across all the implementing types. In order to do this, we have added a new argument interface of boolean type in the @id field.

Whenever a @id field in interface type has an interface argument set then its value will be unique across all the implementing types. Users will get errors if they try to add a node with such a field and there is already a node with the same value of that field even in some other implementing types. This is true for other scenarios like adding nested value or while using upserts.

If the interface argument is not present or its value is false then that field will be unique only for one implementing type. But such fields won't be allowed in argument to get query on interface in the future, see this PR also #7602

Example Schema,

interface LibraryItem {
refID: String! @id // This field is unique only for one implementing type
itemID: String! @id(interface:true) // This field will be unique over all the implementing types inheriting this interface
}

type Book implements LibraryItem {
title: String
author: String
}
Related discuss Post: https://discuss.dgraph.io/t/uniqueness-for-id-fields-on-interface/13294

Cherry picked from: #7710

@CLAassistant
Copy link

CLAassistant commented Jun 14, 2023

CLA assistant check
All committers have signed the CLA.

@dgraph-bot dgraph-bot added area/core internal mechanisms area/graphql Issues related to GraphQL support on Dgraph. area/testing Testing related issues go Pull requests that update Go code labels Jun 14, 2023
graphql/e2e/auth/debug_off/debugoff_test.go Outdated Show resolved Hide resolved
graphql/e2e/auth/debug_off/debugoff_test.go Show resolved Hide resolved
graphql/e2e/common/mutation.go Outdated Show resolved Hide resolved
graphql/resolve/add_mutation_test.yaml Show resolved Hide resolved
graphql/resolve/mutation_rewriter.go Show resolved Hide resolved
graphql/resolve/mutation_rewriter.go Outdated Show resolved Hide resolved
@harshil-goel harshil-goel changed the title Feat(GraphQL): This PR allows @id field in interface to be unique acr… Feat(GraphQL): This PR allows @id field in interface to be unique across all implementing types Jul 6, 2023
@harshil-goel harshil-goel force-pushed the harshil-goel/id-interface branch 2 times, most recently from ed302d5 to 8b46cbb Compare July 6, 2023 09:58
…oss all the implementing types. (#7710)

Currently, @id fields in the interface are unique only in one implementing type. But there are several use cases that require @id field to be unique across all the implementation types. Also currently. get a query on the interface can result in unexpected errors as we can have multiple implementing types have the same value for that @id field.

Now we are allowing the @id field in the interface to be unique across all the implementing types. In order to do this, we have added a new argument interface of boolean type in the @id field.

Whenever a @id field in interface type has an interface argument set then its value will be unique across all the implementing types. Users will get errors if they try to add a node with such a field and there is already a node with the same value of that field even in some other implementing types. This is true for other scenarios like adding nested value or while using upserts.

If the interface argument is not present or its value is false then that field will be unique only for one implementing type.
But such fields won't be allowed in argument to get query on interface in the future, see this PR also #7602

Example Schema,

 interface LibraryItem {
    refID: String! @id                   //  This field is unique only for one implementing type
    itemID: String! @id(interface:true)    // This field will be unique over all the implementing types inheriting this interface
}

type Book implements LibraryItem {
    title: String
    author: String
}
Related discuss Post: https://discuss.dgraph.io/t/uniqueness-for-id-fields-on-interface/13294
graphql/e2e/auth/debug_off/debugoff_test.go Show resolved Hide resolved
graphql/e2e/directives/schema.graphql Show resolved Hide resolved
graphql/e2e/normal/schema.graphql Show resolved Hide resolved
graphql/resolve/add_mutation_test.yaml Show resolved Hide resolved
graphql/resolve/mutation_rewriter.go Show resolved Hide resolved
graphql/resolve/mutation_rewriter.go Show resolved Hide resolved
graphql/resolve/mutation_rewriter.go Show resolved Hide resolved
graphql/resolve/mutation_rewriter.go Show resolved Hide resolved
graphql/resolve/mutation_rewriter.go Show resolved Hide resolved
Copy link
Contributor

@mangalaman93 mangalaman93 left a comment

Choose a reason for hiding this comment

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

Please don't forget to file JIRA ticket for the pending work. LGTM

@all-seeing-code
Copy link
Contributor

. Also currently. get a query on the interface can result in unexpected errors as we can have multiple implementing types have the same value for that @id field.

Unclear

@harshil-goel harshil-goel merged commit a38fff0 into main Jul 17, 2023
@harshil-goel harshil-goel deleted the harshil-goel/id-interface branch July 17, 2023 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core internal mechanisms area/graphql Issues related to GraphQL support on Dgraph. area/testing Testing related issues go Pull requests that update Go code
Development

Successfully merging this pull request may close these issues.

5 participants