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

Shorthand imports and require.extensions #20

Closed
helfer opened this issue Apr 10, 2016 · 6 comments
Closed

Shorthand imports and require.extensions #20

helfer opened this issue Apr 10, 2016 · 6 comments
Milestone

Comments

@helfer
Copy link
Contributor

helfer commented Apr 10, 2016

It would be nice to be able to import schema definitions with a .graphql extension, but it appears that require.extensions has been deprecated and there are some good reasons not to use it.
If we don't use require.extensions, the .graphql files would have to be transpiled, which requires a bit more setup, but would be more maintainable in the future. The transpilation setup could be mitigated by having a boilerplate and really good documentation. I'm also under the impression that most people are now using Babel by default, so it might not actually be such a big hassle to require a transpilation step.
@stubailo What do you think?

@stubailo
Copy link
Contributor

Yeah I think that would be fine! It's not really Babel though since it's not js right? It would be a separate tool probably that people would link into their gulp setup or whatever.

@helfer
Copy link
Contributor Author

helfer commented Apr 11, 2016

In a discussion I just had with @stubailo, we decided to implement the simplest version for now, which is to write and export an array of Strings. The only thing we have to do is de-duplicate the strings at the end. I'll make a PR implementing this shortly.

@helfer helfer added this to the alpha milestone Apr 11, 2016
@helfer
Copy link
Contributor Author

helfer commented Apr 12, 2016

Here's what it's going to look like:

\\ task.js
export default [`
  type Task {
    id: ID
    text: String
  }
`]; 
// list.js
import Task from './task';
export default [`
  type List {
    id: ID
    name: String
    tasks: [Task]
  }`,
  Task
];
// query.js
import List from './list';
export default [`
  type Query {
    list(id: ID): List
    all_lists: [List]
  }`,
  List
];
// schema.js
import Query from './query';
export default [`
  schema {
    query: Query
  }
`, 
  Query
];
// server.js
import { generateSchema } from 'graphql-tools';
import resolveFunctions from './resolvers';
import schema from './schema';

const executableSchema = generateSchema(schema, resolveFunctions);

// more logic here ...

@stubailo
Copy link
Contributor

I would have expected:

// query.js
import List from './list';
export default [`
  type Query {
    list(id: ID): List
    all_lists: [List]
  }`,
  ...List
];

Are we flattening arrays?

@helfer
Copy link
Contributor Author

helfer commented Apr 12, 2016

Haha, I was just going to edit my post right now :D I implemented it with flattenDeep, but for some reason it doesn't feel right to me, so I changed it to apply the spread like you wrote.

@helfer helfer mentioned this issue Apr 12, 2016
@helfer
Copy link
Contributor Author

helfer commented Apr 12, 2016

Have to export functions that return an array (instead of just exporting an array directly) to allow cyclical imports, but everything else stays the same.

@helfer helfer closed this as completed Apr 12, 2016
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