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

How do I let GraphZahl generate the documentation? #9

Open
Evertt opened this issue Apr 2, 2020 · 5 comments
Open

How do I let GraphZahl generate the documentation? #9

Evertt opened this issue Apr 2, 2020 · 5 comments
Assignees
Labels
enhancement New feature or request Type Resolution

Comments

@Evertt
Copy link

Evertt commented Apr 2, 2020

In the README there's a png that shows that GraphZahl can generate schema documentation for GraphiQL.

GraphiQL screenshot

Now in my project where I'm tinkering a bit with GraphZahl, I'm not using GraphiQL. I'm literally just running XCTests and debugging using print statements. 😅

And I'd like to be able to print this documentation that GraphZahl generates, because I'd like to be able to see what GraphZahl makes of my classes. But I can't figure out how. Can you tell me how?

@nerdsupremacist
Copy link
Owner

nerdsupremacist commented Apr 2, 2020

Sure thing!

So this is actually a feature of GraphQL in general. GraphQL allows type introspection. GraphiQL gets this documentation at runtime.

If you run the following query you can get it as JSON:

query IntrospectionQuery {
  __schema {
    queryType {
      name
    }
    mutationType {
      name
    }
    types {
      ...FullType
    }
  }
}

fragment FullType on __Type {
  kind
  name
  description
  fields(includeDeprecated: true) {
    name
    description
    args {
      ...InputValue
    }
    type {
      ...TypeRef
    }
    isDeprecated
    deprecationReason
  }
  inputFields {
    ...InputValue
  }
  interfaces {
    ...TypeRef
  }
  enumValues(includeDeprecated: true) {
    name
    description
    isDeprecated
    deprecationReason
  }
  possibleTypes {
    ...TypeRef
  }
}

fragment InputValue on __InputValue {
  name
  description
  type {
    ...TypeRef
  }
  defaultValue
}

fragment TypeRef on __Type {
  kind
  name
  ofType {
    kind
    name
    ofType {
      kind
      name
      ofType {
        kind
        name
        ofType {
          kind
          name
          ofType {
            kind
            name
            ofType {
              kind
              name
              ofType {
                kind
                name
              }
            }
          }
        }
      }
    }
  }
}

PS: I just ran graphiql in the browser and saw what query it was sending ;)

@nerdsupremacist
Copy link
Owner

GraphZahl is also actually using GraphQLSwift under the hood. But it doesn't make this very visible on purpose.

If you go to GraphQLSchema+resolve.swift and set a breakpoint you can also see it directly with the debugger

@nerdsupremacist
Copy link
Owner

On the other hand GraphQL Playground can create a graphql schema file.

This could be a useful feature to include

@nerdsupremacist nerdsupremacist self-assigned this Apr 2, 2020
@nerdsupremacist nerdsupremacist added the enhancement New feature or request label Apr 2, 2020
@Evertt
Copy link
Author

Evertt commented Apr 2, 2020

If you run the following query you can get it as JSON:

Thank you, that made it clear to me that I need to start using GraphiQL, because that JSON is huge and I can't use it to quickly look whether it has detected one of my class properties and how it sees it.

@nerdsupremacist
Copy link
Owner

Yeah that's sadly the case.

This also relates to #4 since we want developers to know early when a function or property of theirs looks like it should be included but couldn't

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Type Resolution
Projects
None yet
Development

No branches or pull requests

2 participants