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

Not possible to define sourceType with another objectType #1129

Open
lmanerich opened this issue Aug 22, 2022 · 1 comment
Open

Not possible to define sourceType with another objectType #1129

lmanerich opened this issue Aug 22, 2022 · 1 comment

Comments

@lmanerich
Copy link

Related to the already fixed issue: #1006

It was created a new field to define the resolver item response object. But it is only possible for primitive data types.
Also, would be great to inherite the sourceType by "t.string()" method, so we only need to declare complex data structures. Which can be resolved to NexusGenRootTypes[${sourceType}]

objectType({
    name: 'Post',
    definition(t) {
        t.id('id');
        t.string('label', {
            resolve: PostResolver.label,
            sourceType: 'string',
        });
        t.field('user', {
            type: 'User',
            resolve: PostResolver.user,
            sourceType: 'User',
        });
    },
}

Ends up generating:

export interface NexusGenObjects {
  Query: {};
  Post: { // root type
    id?: string | null; // ID
    label: string
    user: User ///// NOT DEFINED
  }

As a workaround it is possible to declare the type as

sourceType: "NexusGenRootTypes['User']",
@lmanerich
Copy link
Author

If you are trying to make a nullable field you would also need to do this in the workaround version:

sourceType: "NexusGenRootTypes['User'] | undefined",

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

No branches or pull requests

1 participant