graphqlhub icon indicating copy to clipboard operation
graphqlhub copied to clipboard

CORS issue when requesting data

Open iamacatperson opened this issue 5 years ago • 1 comments

When I try to use the code below to fetch data from Reddit...

import { Reddit } from 'graphqlhub-schemas';
import { GraphQLSchema, graphql } from 'graphql';

let schema = new GraphQLSchema({
  query: Reddit.QueryObjectType
});

let query = '{ subreddit(name: "netflix"){newListings(limit: 10) { title score url } } }';
graphql(schema, query).then((result) => {
  console.log(result);
});

I get a CORS error: Access to fetch at 'https://reddit.com/r/netflix/about.json' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

By right https://reddit.com will redirect to the one with www but because of the missing Access-Control-Allow-Origin response header, it doesn't.

Any work around for this?

iamacatperson avatar Mar 04 '19 03:03 iamacatperson

@iamacatperson I also encountered same issue. Did you find solution ?

onyxnl avatar Mar 13 '19 06:03 onyxnl