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

fix: possible circular reference when using custom types #109

Open
waspeer opened this issue Nov 5, 2020 · 1 comment
Open

fix: possible circular reference when using custom types #109

waspeer opened this issue Nov 5, 2020 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@waspeer
Copy link

waspeer commented Nov 5, 2020

🐛 The bug
I'm working on a schema that contain section and page document types. A section contains an array of references to page and a page contains a reference to a section. When adding the custom types like described in the documentation the typechecking breaks (everything is infered as any). When I replace the custom type with a plain object like { _type: 'page' } the type inference (partly) works again, so this probably has to do with the fact that section and page reference each other causing it to break.

🛠️ To reproduce
Steps to reproduce the behavior:

  1. Create two documents with a reference field
  2. Reference the documents to each other.

For example: https://gist.github.com/waspeer/f831dbb06ea59f8f8ca04575e1962cf3
Here the type inference of the variables section, page and Rule fail.

ℹ️ Additional context
Thanks for you work on this library!

@waspeer waspeer added the bug Something isn't working label Nov 5, 2020
@waspeer
Copy link
Author

waspeer commented Nov 5, 2020

I wanted to follow up immediately with some possible solutions.

  1. Generate types on runtime. You could generate a CustomType type which consists of all the documents / objects that were defined. An example of this would be @nexus/schema.
  2. Leave it to the user to create a CustomType type. A quick example I could think of would look like this:
// builder.ts

type CustomType = 'section' | 'page';

const { defineDocument, defineObject } = createBuilder<CustomType>()

export { defineDocument, defineObject };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants