jaydenseric / next-graphql-react

A graphql-react integration for Next.js.
https://npm.im/next-graphql-react
MIT License
77 stars 7 forks source link

Examples for withGraphQLConfig #5

Closed modbender closed 4 years ago

modbender commented 4 years ago

Hey, I checked a lots of places for examples of withGraphQLConfig, couldn't find what I needed. I am using django graphene as backend and having url like : http://127.0.0.1:8000/graphql, after checking out some pages all I found is to use fetchOptionsOverride, but I don't want to use it every time I want to call query, is it possible that I put this in one place like next.config.js and it automatically uses it while calling queries? i'm new to nextjs + graphql, have worked with nextjs + apollo + graphql but the page did not prerender instead became csr (maybe I missed some things but this is what I tried : https://github.com/tomanagle/GraphQL-Apollo-Next.js/blob/master/pages/index.js)

jaydenseric commented 4 years ago

There are several examples you can look at:

https://github.com/jaydenseric/graphql-react-examples/blob/e7acc06112c77cf3acc5f0e4ad14cb9cbc54a6f3/config.js#L1

Note the fetch options are centrally configured. In my own apps, I both configure the fetch options override and have my own use_API hook (replace _ with you API name), which wraps useGraphQL and sets the fetch options override from the config.

I don't have a need for static site generation in my projects; if content is coming from my GraphQL API that means it's dynamic - it wouldn't make sense to deploy a static HTML snapshot of that content.

Some people might find it SSG useful, so there is an issue to support it you can track here: https://github.com/jaydenseric/next-graphql-react/issues/4 .

There is no issue for it, but I intend to replace the withGraphQLApp decorator with one that can be applied to either a page or the whole app (the way it works currently).