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

Add support for type system extensions #500

Closed
glen-84 opened this issue Dec 20, 2019 · 1 comment
Closed

Add support for type system extensions #500

glen-84 opened this issue Dec 20, 2019 · 1 comment
Labels
Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists

Comments

@glen-84
Copy link
Contributor

glen-84 commented Dec 20, 2019

Is your feature request related to a problem? Please describe.

I'm considering using the extensions property to mark an object type as being a (Relay) connection, but it's not possible to set this property via the Field or FieldResolver decorators.

I want to do so, so that a resolver can use the GraphQLResolveInfo to determine whether or not an object is a connection, in order to apply special handling during the process of automatically generating a TypeORM query builder.

Describe the solution you'd like

Something like:

@FieldResolver(() => UserCommentsConnection, {extensions: {connection: true}})

i.e. Adding extensions somewhere inside AdvancedOptions.

Describe alternatives you've considered

  1. Using a GraphQL interface, and checking whether or not the type implements this interface.
    • I wasn't sure how to define the interface for Edge, which has a node field. GraphQL doesn't support generics nor an Any type, and I was unsure about creating a custom scalar type just for this purpose (assuming that that would even work).
  2. Trying to access the runtime type of the object, in order to determine whether or not it's an instance of some kind of marker class that connection types extend.
    • I was not able to find a way of accessing the runtime type of the object (only the GraphQL type).
  3. Matching the shape of a connection, by checking for the existence of edges and pageInfo fields.
    • This felt a bit hacky and somewhat fragile, although it is what Join Monster uses.
  4. Using a directive, like @connection.
    • This pushes the responsibility of marking a connection to the client, which is not ideal.
    • It could also conflict with the connection directive in Apollo, etc.

Yet another option, more specific to TypeGraphQL, would be for TypeGraphQL to automatically put the return type somewhere inside extensions. For example:

Given:

@FieldResolver(() => UserCommentsConnection)

TypeGraphQL would add:

extensions: {
    typeGraphQlMetadata: {
        type: UserCommentsConnection
    }
}

... to the GraphQL type, which would enable alternative #2 above, as well as make alternative #3 a little bit easier.

There may be better options that I've not yet considered.

Additional context

n/a

@MichalLytek
Copy link
Owner

Duplicate of #124 🔒
The title might be misleading but the way of putting additional stuff into the types evolved from "hack" of just placing the properties into the object to a dedicated "extensions" property with a dictionary.

@MichalLytek MichalLytek added Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists labels Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants