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

Add printFineSchema() for printing hierarchy ordered types. #281

Closed
wants to merge 2 commits into from

Conversation

iamchenxin
Copy link
Contributor

Add printFineSchema() for printing hierarchy ordered types,the ranks are determined by reference/extends between each type.
Not modify the original printSchema.
Something like :

C {  a:A }
B {  c:C }
A {}

will be ordered to their hierarchy , more details is in tests

A {}
C {  a:A }
B {  c:C }

@leebyron
Copy link
Contributor

leebyron commented Feb 2, 2016

Thanks for assembling this, this is really awesome.

I'm curious why you think printSchema and printFineSchema should both exist? With the existence of this new method, when would you explicitly want to use printSchema instead?

@leebyron
Copy link
Contributor

leebyron commented Feb 2, 2016

Also, I'm curious about the primary motivation. Are you looking for printSchema to be stable as types evolve? If so, perhaps alphabetical may be better as a schema could add interfaces to types as it evolves which could thrash a file.

Or are you just looking to see these printed in a way that is easier to read in the output?

@iamchenxin
Copy link
Contributor Author

@leebyron I write printFineSchema for easier to read the output types. Im not sure if the printSchema have other usages other than output types for reading. So i add an additional function to print readable types. With lots of types, alphabetical will become hard to read.

@iamchenxin
Copy link
Contributor Author

@leebyron hello, is this suitable for merge? Cause im poor at english, if i have some misunderstanding about your meaning,please forgive me.
I make the printSchma like this, by default it print schema by alphabet, or explicitly indicate printing by hierarchy(to get a readable schema).

// type printStyle = 'alphabet' | 'hierarchy';
export function printSchema(
  schema: GraphQLSchema,style: string = 'alphabet'): string {
  switch (style) {
    case 'hierarchy':
      return printFineSchema(schema);
    case 'alphabet':
    default:
      return printFilteredSchema(schema, isDefinedType);
  }
}

@leebyron
Copy link
Contributor

What I'm trying to understand is the purpose - the "why" of this method. Have you added it because it should definitely exist in parallel to the existing printSchema method, or simply out of precaution to have this diff be only additive? When would you use printSchema and when would you use printFineSchema?

@iamchenxin
Copy link
Contributor Author

Maybe it is some personal usage for me(just a few people need this).
The printFineSchema output a hierarchy ordered type. just for human reading .I should move these code to some package called graphql-utils.

…are determined by reference/extends between each type

make printSchema print schma in two style(alphabetical or hierarchy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants