Realm GraphQL error when executing queries: "cannot find app using Client App ID $CLIENT_ID"

Hello!

I am attempting to execute queries on a newly created collection via the GraphQL api using Apollo.

The frontend auths via an API key, the call to get an access token is successful.
When attempting to run any queries after this I can see the bearer token appended however every call returns a 404 and the error:

cannot find app using Client App ID $CLIENT_ID

The full error details are here:

{
    "graphQLErrors": [],
    "clientErrors": [],
    "networkError": {
        "name": "ServerError",
        "response": {},
        "statusCode": 404,
        "result": {
            "error": "cannot find app using Client App ID $MY_CLIENT_ID
        }
    },
    "message": "Response not successful: Received status code 404"
}

I’ve verified that the client ID is correct. I’ve attempted to delete the entire cluster and re-create it in another region with no luck.
Is there some issue with locating newly created clusters or is there some configuration in the UI I am missing?
I am able to access the console at http://cloud.mongodb.com/ and I can successfully run queries in GraphiQL there.
I am aware there is an old thread about this though this issue seems to have resurfaced

fwiw auth code is as follows:

async function getValidAccessToken() {
  if (!app.currentUser) {
    console.log("getting api key creds");
    await app.logIn(Realm.Credentials.apiKey(API_KEY));
    console.log("got credentials!");
  } else {
    await app.currentUser.refreshCustomData();
    console.log("refreshed");
  }
  return app.currentUser?.accessToken;
}
export const apolloClient = new ApolloClient({
  link: new HttpLink({
    uri: `https://realm.mongodb.com/api/client/v2.0/app/${APP_ID}/graphql`,

    fetch: async (uri, options) => {
      console.log("fetching");
      const accessToken = await getValidAccessToken();
      console.log(accessToken);
      (
        options?.headers as Record<string, string>
      ).Authorization = `Bearer ${accessToken}`;
      return fetch(uri, options);
    },
  }),
  cache: new InMemoryCache(),
});
1 Like

I’m having the same issue.

Did you have any luck with this?
What was your outcome?

Thanks

I am having the same issue intermittently. This is a BIG showstopper if this error continues.

Need to know if Graphql will be reliable for my app, as this is the main reason I’m using Atlas App Service. If this cannot be resolved soon, I may find a completely different solution.

Where I went wrong was deploying in a single reagon but referencing it globally. It only made error sometimes on some computers when on some networks.

Having an application deployed in a single region is better in terms of performance than having the application deployed globally.

Therefore, the recommendation (i think) is to keep the app in a single region and use a local URL
EG:
https://ap-southeast-2.aws.realm.mongodb.com/api/client/v2.0/app/(APP_ID)/graphql
INSTEAD OF:
https://realm.mongodb.com/api/client/v2.0/app/(APP_ID)/graphql

3 Likes

This actually worked.
The official docs definitely need to be updated to call this out. Thank you.

2 Likes

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

Hi @Zanek_shaw, @Try_Catch_Do_Nothing ,

Thank you for helping and bringing this to our attention. Your feedback is important to us and this has been reported to the concerned team.

The section “Setting up Apollo Client” will be updated to have both local and global urls.

Thank you again for your contributions.

Cheers, :performing_arts:
Henna

1 Like