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

Proposal: Automatic imports #130

Open
timsuchanek opened this issue Apr 9, 2018 · 2 comments
Open

Proposal: Automatic imports #130

timsuchanek opened this issue Apr 9, 2018 · 2 comments

Comments

@timsuchanek
Copy link
Contributor

When using graphql-import together with a Prisma Service, a common situation that a developer finds herself in is copying over type names.

This happens when you just want to "forward" the underlying service types to the resulting application schema.

While the current explicit nature of graphql-import provides good readability and maintainability, it requires in certain cases a lot of boilerplate code.

To make it possible for developers to have quicker iterations on schemas, we should introduce an automatic import mechanism.

That means, that any type used in the resulting schema, that is not defined, will be searched in specified source files.

The API could look like this:

const typeDefs = importSchema('schema.graphql', ['./generated/source.graphql'])

schema.graphql

type A {
  # test 1
  first: String
  second: Float
  b: B
}

./generated/source.graphql

type B {
  hello: String!
}

Anyone interested working on this, please answer in this issue or join our public Graphcool slack!

@mxmzb
Copy link

mxmzb commented May 7, 2018

I like this very much. You could simplify the API even further and just pass multiple files to importSchema without telling what's the main file. It would be simply in the obligation to pass the files in the correct order.

For this to work I also imagine would be kind of easy and could eliminate the need for comment imports from the .graphql files themselves: Just read the file contents and join them together before parsing as graphql.

@SpaceK33z
Copy link
Collaborator

SpaceK33z commented May 10, 2018

This is certainly interesting for me, since in the app I'm building the comment imports are getting bigger and bigger.

Often you don't want everything from the imported schema, see for example this:

schema.graphql

type User {
  id: ID!
  email: String!
  # The `password` field is purposefully left out here, since we want to hide it!
}

./generated/prisma.graphql

type Query {
  user: User
  users: [User!]
}

type User {
  id: ID!
  email: String!
  password: String!
}

So with those two files as input, what would be the output? In the usecases I've encountered most so far with Prisma I'd really hope it to be this:

output.graphql

type Query {
  user: User
  users: [User!]
}

type User {
  id: ID!
  email: String!
}

I hope I didn't misunderstand this proposal 😄. It could be really powerful!

Also related to this is #51.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants