Git Product home page Git Product logo

Comments (4)

giulianok avatar giulianok commented on September 24, 2024 11

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.

biggytech avatar biggytech commented on September 24, 2024

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.

biggytech avatar biggytech commented on September 24, 2024

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.

indykoning avatar indykoning commented on September 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.