Using GraphQL Code Generator with Realm Will Produce "@deprecated"

GraphQL Code Generator is a great, widely-used, must-have tool for every developer who uses both TypeScript and GraphQL.
However, there’s a minor problem if you use it in combination with Realm GraphQL.

The Problem

All of the fields of the generated types will be marked with @deprecated directives like this:
image

That will have your editor strikes through the params, which look like this:
image

Situation (How to Reproduce)

First of all, when you use the generator, you will specify the location of the GraphQL schema in its config file (e.g. codegen.yml). And the location can be either a remote GraphQL endpoint or a locally downloaded schema file.

So there are two options for Realm GraphQL developers.

  1. Download the schema.graphql file from the button on the Realm UI > GraphQL > Schema tab.
  2. Use the remote endpoint (i.e. https://realm.mongodb.com/api/client/v2.0/app/something/graphql).

If you choose #1 option, there’s no problem. But if you choose #2 option, the deprecation will happen.

FYI: as you know, you will have to set correct headers to fetch the remote schema. My codegen config file starts with like:

schema:
  - ${REALM_GRAPHQL_ENDPOINT}:
      headers:
        apiKey: ${REALM_API_KEY}

And it works without problem, except for the @deprecated thing.

Questions

  • Is the problem recognized/expected?
  • Is there any other correct endpoint to fetch the schema file?

If I’m missing something, I’d appreciate your pointing out.

1 Like

Hey @Toshi - thanks for calling this out, did you see this start happening recently?

It seems like GraphQL Codegen adds this flag when we specify a ‘@deprecated’ directive in the GQL schema. However, MongoDB Realm does not use directives at the moment and downloading my schema from the endpoint (e.g. from GraphQL Playground) does not seem to indicate this either.

It would make sense to file an issue with GraphQL Codegen and understand whether this is a bug/regression/feature request for them, or at least give us more information to why our service doesn’t work with their tooling.

Hi Sumedha, thanks for the immediate feedback like always!

Until reading your comment, I was thinking Realm guys intentionally marked the schema deprecated for some reason, because I have never experienced this issue when I work with other services/frameworks which exposes graphql endpoints.

Now I think, however, it should make sense as you said – the cause may exist on the graphql-codegen side. I’ll go to their repo and find a next step.

FYI, as for your question:

did you see this start happening recently?

No, I have experienced this @deprecated issue since the first time I started to work with Realm GraphQL, which was August. (It’s only August so you can say it’s “recent” :sweat_smile:)

I just came up with an idea to give it a shot with another tooling, which is different from GraphQL Code Generator, to see whether the issue will be reproduced. And it seems reproduced. Below is what I tried with apollo CLI: GitHub - apollographql/apollo-tooling: ✏️ Tooling for development and production Apollo workflows

All I did was running a single line command to download the remote schema:

npx apollo client:download-schema myschema.graphql \
--endpoint="https://realm.mongodb.com/api/client/v2.0/app/yourapp/graphql" \
--header="apiKey: XXXyyyZZZ"

Then a myschema.graphql file was downloaded, and it was deprecated like this:
image

*Just in case, I tried with another command apollo schema:download to get a .json file instead, the result was the same.

What do you think?

Thanks for digging deeper into this - we’re investigating where in our remote schema these “deprecated” flags might be coming from and will update this thread as soon as we find out.

1 Like

Thanks! Looking forward to it to be solved.

1/15/2020 Update - This should be resolved now, cc: @Toshi

@Toshi It looks like the tools started using deprecationReason to assign the @deprecated flag and our GraphQL library was not updated to reflect this change. The fix should be released early next month.

2 Likes

Very cool! Thank you for updating. I’m looking forward to seeing the fix!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.