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

leo-plugin-github #146

Open
ChristopherBiscardi opened this issue Oct 6, 2016 · 3 comments
Open

leo-plugin-github #146

ChristopherBiscardi opened this issue Oct 6, 2016 · 3 comments

Comments

@ChristopherBiscardi
Copy link
Member

There should be a GitHub plugin to make requests to their GraphQL API. Such a plugin could be implemented as the github key in the GraphQL Schema, which would encompass GitHub's entire GraphQL.

{
  root: {
    github: {
      viewer {
        login
        bio
        organizations(first: 3) {
          edges {
            org:node {
              name
            }
          }
        }
      }
    }
  }
}

The main challenge here is recreating the GitHub GraphQL Schema so that queries can be passed through. Can we do an introspection passthrough? (ie: "mount" the passthrough API at github, which when we generate our schema, just goes and fetches the introspection data from GitHub).

Mounting the Schema is the preferred approach so that we do not have to manually recreate and maintain the entire schema in the plugin.

The plugin should handle passing the raw query through to github and dealing with the response appropriately.

@KyleAMathews
Copy link

Related: graphql/graphql-js#490

@ChristopherBiscardi
Copy link
Member Author

consume the introspection query and auto-construct the schema locally

I think I've successfully prototyped a merged Introspection query that monkey-patches the GitHub GraphQL API. I sure as hell wouldn't use it in a production webapp (hackkkkkkk), but for LEO/Gatsby it might be useful? I do believe it can also be written out directly and used in a Relay client to validate queries.

Step 2, which is what I'm working on right now, is to hijack express-graphql's introspection query and return the data so that Graphiql can use it. I have no idea if this is going to work and if it does it's an even hackier hack than merging the introspection queries.

Step 3 is to parse the request body ahead of express-graphql's handling and finagle the AST to rip out the github query, then remount it on it's own query and send it to github to return the appropriate data.

@ChristopherBiscardi
Copy link
Member Author

> node index.js
# introspection types for the base schema
[ 'Query',
  'String',
  '__Schema',
  '__Type',
  '__TypeKind',
  'Boolean',
  '__Field',
  '__InputValue',
  '__EnumValue',
  '__Directive',
  '__DirectiveLocation' ]
# length of types for base and github schema respectively
11 184
# skipping types that are basic and exist in both places
skipping String
skipping Boolean
185

The final number is the length of the merged introspection query's types, which is correct because a new type is created from GitHub's Query type (renamed to GitHubQuery and remounted) while the original Query type is preserved and added-to.

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