Skip to content

Explore possibility of generic types #415

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

Closed
AndrewIngram opened this issue Jun 28, 2016 · 2 comments
Closed

Explore possibility of generic types #415

AndrewIngram opened this issue Jun 28, 2016 · 2 comments

Comments

@AndrewIngram
Copy link

AndrewIngram commented Jun 28, 2016

As projects like Relay have shown, it's relatively common to repeat the same generic structures of types multiple times within a project. In the case of Relay, I'm talking about Connections.

The GraphQL definition language already has explicit support for one particular form of generic type, arrays:

type Foo {
   id: ID!
   bars: [Bar]
}

I'd like to start discussion about being able to do something similar for user-defined structures:

generic ConnectionEdge<T> {
   node: T
   cursor: String
}

generic Connection<T> {
   edges: ConnectionEdge<T>
   pageInfo: PageInfo
}

type Foo {
   id: ID!
   bars: Connection<Bar>
}

The overall goal is to reduce the amount of boilerplate in creating schemas with repetitive structures.

@AndrewIngram
Copy link
Author

Realised this should be on the spec repo, moving: graphql/graphql-spec#190

@langpavel
Copy link
Contributor

Hey, nice!
But if you don't use GraphQL language itself but you create this schema on runtime, you only need higher order function as this is already done in graphql-relay.
BTW every used generic type must be materialized somewhere, so can this be really useful?

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

2 participants