urql-graphql / urql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
https://urql.dev/goto/docs
MIT License
8.6k stars 448 forks source link

urql dosn't respect prefergetmethod value and always send post requests #3295

Closed OmarShref closed 1 year ago

OmarShref commented 1 year ago

Describe the bug

urql dosn't respect prefergetmethod value and always send post requests what ever the value that is given to it

Reproduction

"use client"; import Category from "./Category"; import { Client, Provider, cacheExchange, fetchExchange } from "urql"; const client = new Client({ url: "https://v2-api.alsaifgallery.com/graphql", exchanges: [cacheExchange, fetchExchange], preferGetMethod: "force", requestPolicy: "network-only", fetchOptions: { headers: { store: storeCode, }, }, }); const CategoryWrapper = ({ categoryId, storeCode, categoryName, initialCategoryData, }) => { return ( <> <Category categoryId={categoryId} categoryName={${categoryName}} storeCode={${storeCode}} initialCategoryData={initialCategoryData} /> </> ); }; export default CategoryWrapper;

Urql version

"eslint": "8.40.0",
"eslint-config-next": "^13.4.5",
"next": "^13.4.5",
"range-slider-input": "^2.4.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-responsive-carousel": "^3.2.23",
"sharp": "^0.32.1",
"urql": "^4.0.4",
"zustand": "^4.3.8"

Validations

kitten commented 1 year ago

See: https://github.com/urql-graphql/urql/commit/d17a1c256a04655b05006539dd69a0813e2f51c4

This is working just fine as far as I can tell.

Please do note, if you have a question, we've got Discord and GH Discussions available, but issues are reserved for bugs where you have a clear reproduction or path/reason to believe it's not a usage issue 😅

On a side note, I obviously don't know what you're up to or need, but please keep in mind that settings requestPolicy: "network-only" on the Client as a default, as per the TSDocs notes, is not recommended and will likely not lead to the behaviour you expect. That said, it's unrelated to this issue.

You've posted code above, but that's not a proper reproduction, however, it's also not functional code. So, I can only assume that since the client is "free-floating" there that you may have duplicate clients or duplicate places where you may define its configuration, and I'm not sure whether preferGetMethod is applied to the Client that's used. Does that sound plausible to you? 🤔

I'll go ahead with closing this for now, but obviously, feel free to keep responding here and I'm happy to help how I can :v: