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

Root type identifier #359

Open
chertkovalex opened this issue Apr 19, 2022 · 3 comments
Open

Root type identifier #359

chertkovalex opened this issue Apr 19, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@chertkovalex
Copy link

As mentioned in documentation,

it is recommended that every uniquely identifyable concept in your application, does have an id field of the graphQL ID type. By default, any object types for which this is true, is considered to be a "root type"

Our schema:

type DemoMessage {
  key: ID!
  id: Float!
}

Is generated model.base:

    key: types.identifier,
    id: types.union(types.undefined, types.number),

For specific business purposes we can't use an id field as an identifier. In our case, we have a filed called key which is an identifier, but the object is not considered as a root type. Is there any way to specify that identifier field should not only to be an id for detecting root types?

@beepsoft
Copy link
Collaborator

Unfortunately id is hard coded and the runtime only looks for this field in the graphql query results to identify the objects.

@jesse-savary
Copy link
Member

That might be something we can change. I'll investigate as I want mst-gql to be as backend-agnostic as possible

@beepsoft
Copy link
Collaborator

beepsoft commented Apr 23, 2022

That would be great.

One thing that also worth considering is not to stick to requiring the id field to be of type ID. In case of Hasura the id fields will be a scalar type named after the postgres type of the id field, eg. bigint or uuid. --fieldOverrides seems to provides a solution for this, but it is a generic and not related to id-, which need specific attention as the automatic root type detection algorithm looks for specifically the field id and ID! type. So --fieldOverrides only works together with --roots in case of id field overrides.

function autoDetectRootTypes() {
return types
.filter(
(type) =>
objectTypes.includes(type.name) &&
type.fields.some(
(field) =>
field.name === "id" &&
skipNonNull(field.type).kind === "SCALAR" &&
skipNonNull(field.type).name === "ID"
)
)
.map((t) => t.origName)
}

Moreover it maybe useful to allow specifying id field name per root entity as different entities may have different id fields, eg. some called id others called key, etc.

@jesse-savary jesse-savary self-assigned this Nov 6, 2022
@jesse-savary jesse-savary added the enhancement New feature or request label Nov 6, 2022
@jesse-savary jesse-savary added this to the v0.19.0 milestone Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants