nicolasdao / schemaglue

Naturally breaks down your monolithic graphql schema into bits and pieces and then glue them back together.
BSD 3-Clause "New" or "Revised" License
116 stars 13 forks source link

Using fragment with schemaglue #6

Closed dark06 closed 6 years ago

dark06 commented 6 years ago

Hello,

I want to define some fragments for specific schema. How is this possible? Can you give an example on how to implement that.

I am currently using the mock_02 version of defining schema and resolver

Thanks

bryanlvenable commented 6 years ago

I am also looking to use fragments. I want to be able to import input types from other schema files. Is this possible with schemaglue?

nicolasdao commented 6 years ago

Hi @dark06 and @bryanlvenable ,

I'm not sure I understand your question. To my knowledge, fragments are used to break down your GraphQL request (https://graphql.org/learn/queries/#fragments). ShchemaGlue allows to break down your GraphQL schema. I don't really understand how fragments fit into the GraphQL schema.

Would you mind to clarify your question?

Thanks a lot,

Nic

bryanlvenable commented 6 years ago

Apologies @nicolasdao, I am still learning GraphQL and it's terminologies. I think I meant was interfaces, not fragments. I want to be able to define an interface one one .graphql file and import it to implement in other files.

For example

// characters/schema.graphql
interface Character {
  id: ID!
  name: String!
  friends: [Character]
  appearsIn: [Episode]!
}
// humans/schema.graphql

import { Character } from '../characters/schema');
// or
const Character = require('../characters/schema');

type Human implements Character {
  id: ID!
  name: String!
  friends: [Character]
  appearsIn: [Episode]!
  starships: [Starship]
  totalCredits: Int
}

https://graphql.org/learn/schema/#interfaces

bryanlvenable commented 6 years ago

@nicolasdao I went ahead and just tried it out, and it looks like I can get the functionality I wanted without require or import statements. Defining a type or interface in one .graphql file can be used in another. Please consider my side of this issue ticket satisfied. Thanks for the awesome library, it is helping my code look clean and be easy to maintain and develop.

nicolasdao commented 6 years ago

Hi @dark06 ,

I think the answer of @bryanlvenable above should also fix you up. Does that make sense?