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

Ability to exclude Query, Mutation and Subscription types from imported schema #205

Open
atten opened this issue Jul 27, 2018 · 6 comments

Comments

@atten
Copy link

atten commented Jul 27, 2018

This feature would be useful when we have types and inputs generated by Prisma, and want to add custom implemented Query and Mutation for real-world app.

For example:

const { importSchema } = require("graphql-import");
const { GraphQLServer } = require('graphql-yoga');
const { mergeTypes } = require("merge-graphql-schemas");

const typeDefs = mergeTypes([
  importSchema(`# import * from './src/graphql/generated/prisma.graphql'`),
  readFileSync('./src/common/schema.graphqls', {encoding: 'utf-8'}),
  readFileSync('./src/auth/schema.graphqls', {encoding: 'utf-8'}),
  ...
], { all: true });

const server = new GraphQLServer({
  typeDefs,
  ...
});

But now I can't do that because importSchema grabs generated Query and Mutation types directly into application API.

@atten
Copy link
Author

atten commented Jul 27, 2018

I've made a fork, that works exactly as I need.

It has one difference in index.ts:

  document.definitions = completeDefinitionPool(
    flatten(allDefinitions),
    [],  // empty array instead of "firstSet"
    flatten(typeDefinitions),
  )

@FluorescentHallucinogen
Copy link

@Siyfion
Copy link

Siyfion commented Aug 3, 2018

@atten I think I'm right in saying that if the imported file has any duplicate type (including type Query) it won't import the duplicate. So if you merged your readFileSync lines and then unshift on the import, I think you get this for free.

@atten
Copy link
Author

atten commented Aug 3, 2018

@Siyfion unfornunately, graphql-import does import duplicates.

I've tried to transform import like this, but got multiple errors
Field Mutation.%s can only be defined once.

let typeDefs = mergeTypes([
  readFileSync('./src/common/schema.graphqls', {encoding: 'utf-8'}),
  readFileSync('./src/auth/schema.graphqls', {encoding: 'utf-8'}),
 ...
], { all: true });

typeDefs = importSchema(typeDefs + `
  # import * from './src/graphql/generated/prisma.graphql'
  `
);

@Siyfion
Copy link

Siyfion commented Aug 3, 2018

@atten I've done exactly this and it's working fine...? :/
The only thing I can see different is that I have my # import lines at the top of my SDL file.

@lastmjs
Copy link

lastmjs commented Oct 17, 2018

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

5 participants