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

Types is overwriting instead merging #31

Open
gabrielxavier-hotmart opened this issue Oct 9, 2019 · 1 comment
Open

Types is overwriting instead merging #31

gabrielxavier-hotmart opened this issue Oct 9, 2019 · 1 comment

Comments

@gabrielxavier-hotmart
Copy link

Hi,

I using grahpQL Modules and all my schema.graphql are separeted in modules.
My problem is:
I have one type in one module, after this, i declare this type again injecting other property.
But when i generat the interfase only the last type is considered.
Example

In Doctor Module:
type Doctor {
id: ID!
name: String!
birth: String
}

In Specialty Module:
type Doctor {
specialties: [Specialty]
}

Bu when i generate interfaces:
export interface GQLDoctor {
specialties?: Array<GQLSpecialty | null>;
}

I use this function to merge schemas:

const genSchema = async () => {
	const schemas: GraphQLSchema[] = [];
	const folders = readdirSync(join(__dirname, "../modules")).filter(f => !f.includes("."));

	folders.forEach(folder => {
		const typeDefs = importSchema(join(__dirname, ../modules/${folder}/schema.graphql`));
		schemas.push(makeExecutableSchema({ typeDefs }));
	});
	await generateTypeScriptTypes(
		mergeSchemas({ schemas }),
		join(__dirname, "../types/schemas.d.ts")
	);
};
@dangcuuson
Copy link
Owner

Hi there,

Assume the mergeSchemas comes from graphql-tools, maybe you need to resolve type conflict

Alternately, instead of merging schema, you may consider extends your type instead

e.g: Add extends keyword in Specialty Module:

extends type Doctor {
  specialties: [Specialty]
}

And combine all your type defs into one schema only

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