Comments (4)
Here are some ideas:
- The
add
function could always rename the variables and add a postfix, e.g.id -> id_0
to avoid collision - Accept "global variables" in the
combineQuery
function and use them in all queries
from graphql-combine-query.
I combine queries with combineQuery
function + add
and I don't pass variables there, I pass them in apollo's useQuery
afterwards like this:
// query.js file
const queries = []; // some imported queries here, that use common variables
const getQuery= () => {
let combinedQuery = combineQuery("Query");
queries.forEach((query) => (combinedQuery = combinedQuery.add(query)));
return combinedQuery.document;
};
const query = getQuery();
// inside some component
const {loading, error, data} = useQuery(query, { // imported query here
variables: {...someVariables},
});
And after that I get duplicate variable definition variable for operations Query1 and Query2
error.
Does anyone know a workaround to fix this?
from graphql-combine-query.
I solved this issue with fragments without graphql-combine-query
lib, like was mentioned here: apollographql/graphql-tag#169 (comment)
const oneQuery = gql`
query Query(
$variable: String!
) {
...firstFragment
...secondFragment
}
${firstFragment}
${secondFragment}
`;
from graphql-combine-query.
Here are some ideas:
- The
add
function could always rename the variables and add a postfix, e.g.id -> id_0
to avoid collision- Accept "global variables" in the
combineQuery
function and use them in all queries
I agree.
In my case i want to do multiple mutations on a cart which uses the cart_id
variable which is always the same.
maybe we could add the ability to configure how it can resolve conflicts:
{
allow_duplicates: ["cart_id"],
suffix_duplicates: true
}
This way by default it would still throw the error.
If you allow a duplicate it may be nicer to you with variables you consider global, but still throw errors if you for example try and set both the billing and shipping address of someone using $address
which would certainly not be intended behavior
And if you set suffix duplicates to true it will stay quiet and simply add an incrementing counter to these variables
from graphql-combine-query.
Related Issues (10)
- Package name is misspelled in package.json HOT 4
- dist version HOT 2
- initial empty query ? + node_module warning
- Hello guys. Can load async or sync when combine graphql query ?. Thank all guys
- Error : TypeError: combineQuery is not a function
- Installing this library causes errors when compiling
- browser usage HOT 1
- Support for same field in different queries HOT 2
- Overlapping queries / Duplicate top-level fields not allowed? HOT 2
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-combine-query.