Comments (7)
Ah got it. I've been using Django graphene GraphQL backend. I suspect it's how Django handling cors resulting in this error. I'll work on that part.
I will close this now, comment on this in case of an update. Hopefully this resolves cors issue and data fetching from django graphql api into nextjs. Thanks for your help. Appreciate this library you've developed.
from graphql-react.
I don't think options.mode = 'no-cors'
is a real option:
- https://github.com/jaydenseric/graphql-react#type-graphqlfetchoptions
- https://github.github.io/fetch/#options
from graphql-react.
Thanks for responding.
Using localhost graphql api resulted in "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8000/api/graphql/. (Reason: CORS request did not succeed)." error.
Originally I tried all the options I could, including following.
const Index = () => {
const {loading, cacheValue = {}} = useGraphQL({
fetchOptionsOverride(options) {
options.url = 'http://localhost:8000/api/graphql/'
// options.credentials = 'same-origin'
},headers :{ "Access-Control-Allow-Origin" : "*" }, operation: { query: `
{
allArticles {
id
} }`
} })
With trial and error, for some reason using mode: 'no-cors', gets rid of the message. Now I understand it's not an option to be used.
Using external api seems to work well with the example.
Can you please point me towards right direction how to get localhost:8000 graphql api data into nextjs?
from graphql-react.
Can you please format your code blocks, I can't read that.
from graphql-react.
My bad. Here is the index.js file content. Rest of the code is not changed from "with-graphql-react" example.
import {useGraphQL} from 'graphql-react'
const Index = () => {
const {loading, cacheValue = {}} = useGraphQL({
fetchOptionsOverride(options) {
options.url = 'http://localhost:8000/api/graphql/'
// options.credentials = 'same-origin'
},
headers :{
"Access-Control-Allow-Origin" : "*"
},
operation: {
query: `
{
allArticles {
id
}
}
` }})
return cacheValue.data ? (
<p>Hello</p>
) : loading ? (
<p>Loading…</p>
) : (
<p>Error!</p>
)
}
export default Index
from graphql-react.
headers
is not a valid useGraphQL
option: https://github.com/jaydenseric/graphql-react#function-usegraphql
I don't know why you are having CORS problems, I run my Next.js app at http://localhost:3002
and GraphQL API at http://localhost:3003/graphql
without problems.
from graphql-react.
If anyone using Django graphql backend and using react frontend using nextjs "with-graphql-react" example.
You need to install python package django-cors-headers in your backend and follow the instructions specified in order to avoid cors issue.
from graphql-react.
Related Issues (20)
- hello can you convert for native js? HOT 6
- Document the `load` function HOT 3
- Support automatic persisted queries HOT 2
- How should you implement auth using this library? HOT 8
- Possibly missing files within package HOT 2
- Add ability to load on mount only if no cache HOT 2
- How to move gql query to useGraphQL operation query HOT 1
- Publish the GraphQL client in a separate package HOT 5
- Wrong type calculation on useGraphQL HOT 1
- How to use useGraphQL hooks when handleLoadMore functions trigger? HOT 1
- Allow React component displayName and propTypes to be removed in production builds HOT 3
- Pagination possible? HOT 4
- New composable React hooks HOT 2
- Add a license file HOT 3
- Add ability to clear not currently subscribed cache
- Switch to user defined cache keys
- Publish SSR functionality in a separate package
- error - unhandledRejection: TypeError: Head.rewind is not a function -> can't get the official example to work HOT 3
- How to use useLoading() to get the old loading from useGraphql()? HOT 4
- Clear code
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-react.