Skip to content

buildType function #597

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

Open
langpavel opened this issue Nov 21, 2016 · 2 comments
Open

buildType function #597

langpavel opened this issue Nov 21, 2016 · 2 comments

Comments

@langpavel
Copy link
Contributor

langpavel commented Nov 21, 2016

Why?

You can write entire schema in GraphQL and then call buildSchema. But you cannot write only single type or partials and then combine them simply. Why?

There is some effort:

Example: contentType.graphql:

type ContentType {
  path: String!
  title: String!
  perex: String!
}

Then with today tooling it should be possible to write:

import { ContentType } from './types/contentType.graphql';

export default function createSchema(context) {
  return new Schema({
    query: new ObjectType({
      name: 'Query',
      fields: {
        content: {
          type: ContentType,
          args: {
            path: { type: new NonNull(StringType) },
          },
          async resolve({ request }, { path, locale }) {
            const { success, fileName, extension } = await resolveFileName(path, locale);
            if (!success) {
              return null;
            }

            const source = await readFile(fileName, { encoding: 'utf8' });
            return parseContent(path, source, extension);
          },
        }
      },
  });
}

Goal

Write modules containing types in GraphQL (*.graphql files), then compose this pieces in meaningful schema in your app.

As you see, you can mix pure GraphQL with custom field resolvers — this is only goal of mine.

Now-a-day it is piece of cake to optimize all the things using require/babel/webpack plugins..

@leebyron Can you help me with this a little? What is the right way for modular GraphQL backends? :-)

@migueloller
Copy link

The discussion for graphql-utilities is here: #474

@IvanGoncharov
Copy link
Member

It's a pretty big change that should go through a series of RC to polish interface and ensure it covers the majority of use cases. So it should be planned for 15.0.0

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

4 participants