Graphql endpoint for codegen

Hi
I see monday.com has it’s api schema shared at https://api.monday.com/v2/get_schema.
But this only shares a JSON representation of the api.

I however am trying to run graphql codegen to generate a typescript ready file.
So I need the url to the actual graphql schema endpoint.
As can be seen used in the following link Home – GraphQL Code Generator.

Can anyone direct me where I can find that please?

Hello @tufvessonr and welcome to the community!

I hope you like it here :muscle:

I am not sure about this one but I will check with our team and let you know when I get a reply!

Cheers,
Matias

Hello again @tufvessonr!

I have checked with our team and we do not provide other representations for the schema.

In this case you would have to convert it to the desired representation on your end.

Cheers,
Matias

I see.

Well that’s to bad.
But thanks for the info @Matias.Monday.

Has anyone suggested to them to add that functionality?
It’s not a security risk issue and the JSON version is already shared.
So I don’t see why they would have an issue with allowing the public access to it.

Benefit wise…
It would make adding typescript to the auto generated integration apis much easier for developers.

Hello there @tufvessonr!

Nobody had suggested this as far as I know but I will share this with our team :slightly_smiling_face:

Thank you for the feedback!

Cheers,
Matias

Hi @tufvessonr ,

I had the same problem, but u can easily convert the json schema into .graphql schema:

const { readFileSync } = require('fs');
const  graphql = require('graphql');

var data = JSON.parse(readFileSync("./schema.json").toString()).data
var schema = graphql.buildClientSchema(data)

console.log(graphql.printSchema(schema));

Hello @halbritter!

Welcome to the community and thank you for sharing that :slightly_smiling_face:

I’m assuming no one’s asking about this feature because they saw the answer on this thread which makes it look like Monday.com isn’t gonna add this functionality.

Even I was debating going through the hassle of creating an account just to ask this question and potentially get zero resolution on it.

90% of people using Monday.com’s GraphQL API will want TypeScript types, and the GraphQL Codegen library is the most-common way to get those types.

I spent quite a long time searching around trying to figure out how to get this working before stumbling on this thread where it looks like Monday.com doesn’t wanna bother providing a simpler endpoint.

If I’m going to have to parse the schema myself and convert it to a different format, then that means I have to use GraphQL Codegen in a way it wasn’t intended.

Is it possible this one endpoint could be added, so it’ll be easier to use Monday.com’s GraphQL API with proper type safety?

1 Like

Another issue, graphql.buildClientSchema doesn’t even exist in the latest version of the library. Now I have to waste more time trying to figure this out when it could be more-simply provided by the API authors.

This is the correct import:

import { buildClientSchema } from 'graphql/utilities'

But the error I received was:

Error: Invalid or incomplete introspection result. Ensure that you are passing “data” property of introspection response and no “errors” was returned alongside: { data: { __schema: [Object] } }.

And this is what’s in the data returns from that get_schema JSON fetch:

{
  data: {
    __schema: {
      queryType: [Object],
      mutationType: [Object],
      subscriptionType: null,
      types: [Array],
      directives: [Array]
    }
  }
}

The proper way to handle this is to call buildClientSchema(data) where data is the jsonResponse.data property:

fetch( 
 'https://api.monday.com/v2/get_schema'
)
.then((
  response,
) => (
  response
  .json()
))
.then(({
  data
}) => (
  buildClientSchema(
    data
  )
))
.then((
  graphQlSchema
) => (
  printSchema(
    graphQlSchema
  )
))

You can also return a promise from your Codegen config. That’s not documented in any of the tutorials I saw, but it worked fine.

Hopefully that helps anyone stuck on this issue.

1 Like

Hello there @Sawtaytoes,

Thank you for sharing your feedback!

A request has been created for our team to add this endpoint. No ETAs at the moment.

I have shared your comments on graphql.buildClientSchema with the team as well so they can take a look :grin:

Cheers,
Matias

Hi All

Exciting news, we expanded how and where you can find our public API schema.

Our GraphQL schema defines the structure of the available API data and contains all of the possible queries and mutations you can use. It is a valuable resource that you can use to verify your API responses and extract useful information from the metadata.

By default, the schema is in introspection JSON format for the current API version and can be found here:

https://api.monday.com/v2/get_schema

It is possible to get the SDL version (schema definition language) of the schema by using the optional parameter “format” with the value “SDL”

In addition, you can request a different version by using the optional parameter “version” with the value of the version name.

For example, you can get the SDL for version 2024-04 on the following URL:
https://api.monday.com/v2/get_schema?format=sdl&version=2024-04"

All this is also available through the monday.com developer center API playground! Find the new schema button where you can get all these variations for all API versions.

Happy Coding!

1 Like

Any word on if/when monday is going to remove the error_code and error_message keys from error responses? They are not compliant with GraphQL spec and make using specification compliant clients on the backend impossible. We really would love to use them since they are able to throw errors from GraphQL errors and we can then handle errors just like anything else. But these extra keys cause them to have internal errors.

All errors should be in an errors object in the response per the spec.

1 Like

We prioritised this issue and it should be fixed soon.

1 Like