CORS issue when creating a post in ComposeDB

Hey all,

I just started integrating ComposeDB into our application and I am facing a CORS issue when trying to push data to the GraphQL server.
Note: Reading from the GraphQL endpoint seems to work.

The logic is really simple for now and looks like this

const composeClient = new ComposeClient({
  ceramic: 'http://localhost:5005',
  definition: runtimeComposite as any,
});

// When the user auth we call
composeClient.setDID(session.did);

// Trying to push some data
const data = await composeClient.executeQuery(
        `
      mutation createPost($input: CreatePostInput!) {
        createPost(input: $input) {
          clientMutationId
        }
      }
    `,
        { input: { content: { title: 'Test' } } }
      );
      console.log('data', data);

In my .ceramic/daemon.config.json I have the following config

 "cors-allowed-origins": [
      ".*"
    ],

Pull request adding composeDB to our project

Do you have an idea where this might be coming from?

I agree with @mohsin in his answer on previous posts regarding CORS: Error: Inconsistent CORS error - #3 by ukstv

In experience from our own app:

  1. CORS errors - especially when inconsistent I have found are when I am hitting a rate limit on some third party services (it works 90% of the time, and then sometimes we get a block of CORS errors). I havenā€™t drilled to the core of the issue yet, but a true CORS error shouldnā€™t really be inconsistent.
  2. I have more issues testing a local API to local FE with CORS sometimes than deploying to a test/staging site live. I canā€™t fully explain this either yet (maybe my fault) but for sanity checks its something to try.
1 Like

By GraphQL server, do you mean the server exposed when by the @composedb/devtools-node APIs or using the composedb graphql:server command from the CLI please?
If so, this is not the URL you need to provide to the ComposeClient parameters, the ceramic value must be the URL of the Ceramic server, not a GraphQL endpoint.

Also please note that the GraphQL server exposed by the devtools is only meant to enable local interactions with the compositeā€™s data when developing apps, notably with GraphiQL. Itā€™s not a server your app should communicate with directly.

Thanks Paul, I was making the calls to http://localhost:5005 which is the GraphQL server exposed by @composedb/devtools-node. Changing this to http://localhost:7007 is working fine.

Maybe a note on this page Performing mutations | ComposeDB on Ceramic can help other devs to not make the same mistake?

1 Like

Thanks Leo, Iā€™ll update the docs to be clearer!

1 Like