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

Expose the GraphQL schema somewhere #41

Closed
simonw opened this issue Aug 8, 2020 · 3 comments
Closed

Expose the GraphQL schema somewhere #41

simonw opened this issue Aug 8, 2020 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@simonw
Copy link
Owner

simonw commented Aug 8, 2020

From this Twitter conversation I learned how to output a GraphQL schema: https://twitter.com/simonw/status/1292193658700144640

Example output here: https://gist.github.com/simonw/21b2f0878d4e4e20d514b8544b296393 - a snippet:

schema {
  query: Query
}

input IntegerOperations {
  eq: Int
  not: Int
  gt: Int
  gte: Int
  lt: Int
  lte: Int
  in: [Int]
  notin: [Int]
  arraycontains: Int
  isnull: Boolean
  notnull: Boolean
  isblank: Boolean
  notblank: Boolean
}

type PageInfo {
  endCursor: String
  hasNextPage: Boolean
}

type Query {
  users(filter: [usersFilter], where: String, first: Int, after: String, sort: usersSort, sort_desc: usersSortDesc, search: String): usersCollection
  users_get(id: Int, filter: [usersFilter], where: String, after: String, sort: usersSort, sort_desc: usersSortDesc, search: String): users
  repos(filter: [reposFilter], where: String, first: Int, after: String, sort: reposSort, sort_desc: reposSortDesc, search: String): reposCollection
  repos_get(id: Int, filter: [reposFilter], where: String, after: String, sort: reposSort, sort_desc: reposSortDesc, search: String): repos
  licenses(filter: [licensesFilter], where: String, first: Int, after: String, sort: licensesSort, sort_desc: licensesSortDesc, search: String): licensesCollection
@simonw simonw added the enhancement New feature or request label Aug 8, 2020
@simonw simonw added this to the 1.0 milestone Aug 8, 2020
@simonw
Copy link
Owner Author

simonw commented Aug 8, 2020

Here's partial code for outputting it:

from graphql import print_schema

    schema = await schema_for_database(datasette, database=database)

    if request.args.get("schema"):
        return Response.text(print_schema(schema))

@simonw
Copy link
Owner Author

simonw commented Aug 8, 2020

According to graphql/graphql-spec#203 (comment) the internal standard file extension for these at Facebook is .graphql.

I'm going to use the URL to the database-specific endpoint with graphql on the end for this, e.g.

https://datasette-graphql-demo.datasette.io/graphql/github.graphql

@simonw simonw closed this as completed in c2e2293 Aug 8, 2020
@simonw
Copy link
Owner Author

simonw commented Aug 8, 2020

simonw added a commit that referenced this issue Aug 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant