'CORS Error with dgraph and apollo graphql

I am unable to run query requests with my local dGraph server.

I am running

  1. dGraph using docker compose with both zero and alpha
  2. React client side frontend using apollo-client graphql for running queries.

dGraph starts up fine, I have connected and run queries/mutations/etc through postman application, but when trying to run the exact same query through apollo it gives "Unable to fetch" error.

Any idea how I can configure either apollo or dGraph to accept CORS requests and ultimately run the query

Note - downloaded and ran the queries through apollo using the browser extension for allowing CORS requests and the UI then runs fine - pointing at the issue being something to do with the CORS configuration



Solution 1:[1]

After a lot of searching, I found that wildcards in the cors configuration on dgraph does not work. It must specify the full url. After specifying http://localhost:3000 then Cors started working

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user3206236