Hi folks, I am looking at interfacing with prefect...
# ask-community
e
Hi folks, I am looking at interfacing with prefect’s graphql API using Typescript and was wondering if the schema for Prefect’s API is available anywhere? Ideally I’d like to autogenerate typescript types for the queries, mutations etc. I’ve tried using
graphql-code-generator
but that hasn’t worked so far
That’s the output from
graphql-codegen
a
@Eddie Atkinson In the UI, there is an interactive API with documentation explorer - you can use it to look up any schema, and write your queries and mutations:
e
I was hoping for something less manual. Ideally I’d like to interface with prefect without having to write and maintain queries and mutations. It would be cool to be able to generate the schema for prefect as part of my CI/CD pipeline
a
@Eddie Atkinson can you describe your use case a bit more? What are you trying to do with Prefect API? I don’t understand what problem are we solving here. Are you looking for auto-completion based on the API schema in your IDE? the CI/CD part confused me the most 🙂
e
Hi @Anna Geller, sorry for disappearing over the weekend. I am looking at creating a set of lambda functions in Typescript to interact with Prefect (the lambda functions are part of a REST API for a front-end) which are used to trigger flow runs etc. I was hoping to auto generate the types for the mutations, queries etc from the Prefect graphql API, but was struggling with the fact that the API is authenticated
For anyone else who struggles with this, this resource from Hasura was very helpful. This is the
codegen.js
file I used to generate the types for the Prefect API:
Copy code
/* eslint-disable */
module.exports = {
  overwrite: true,
  schema: [
    {
      '<https://api.prefect.io/graphql>': {
        headers: {
          Authorization: `Bearer ${process.env.PREFECT_API_TOKEN}`,
        },
      },
    },
  ],
  documents: null,
  generates: {
    'src/generated/graphql.ts': {
      plugins: ['typescript', 'typescript-resolvers'],
    },
  },
};
a
@Eddie Atkinson awesome, glad you figured it out!
👍 1