Easier access to Fauna-generated GraphQL schema (compatible with https://graphql-code-generator.com/)

Hi. I’m using https://graphql-code-generator.com/ (https://www.npmjs.com/package/@graphql-codegen/cli). I am using it with the schema generated by Fauna, since it includes a lot of generated content beyond my original schema, such as scalars, _id, _ts, input types, queries, and so on. It’s a bit annoying to use the FaunaDB GraphQL schema right now, and it would be nice to be improved sometime.

  • (The biggest one) AFAICT I can’t automatically download the FaunaDB graphql anywhere, via a script. I haven’t dug into the dashboard code to see if there’s a better option, but the only thing I see to do is download it manually from the dashboard’s GraphQL. That’s not build-script-friendly. If I missed an option in the docs, please let me know, with my apologies.

  • The doc strings in my original GraphQL have been converted to comments in the Fauna GraphQL export, so that the generated typescript doesn’t have the help.

  • The directives in the GraphQL export confuse the parser. I remove those.

  • There’s an odd newline I have to correct.

    # The Long scalar type
    represents non-fractional signed whole numeric values.

It would be nice to make this easier sometime.

Thanks,
Gary

The way to get a remote schema is to use introspection queries. This is not unique to Fauna, just how you would work with any remote GraphQL server. You can point a graphQL client at the graphql endpoint and send the request in a script. graphql-request, might be a lightweight solution.

introspectSchema is a graphql-tools function that is exported from just about everything apollo.

introspection docs page:

1 Like

Got it, thanks! It’s a bit old, but I had luck with get-graphql-schema as a command line convenience.