GithubHelp home page GithubHelp logo

Comments (4)

dimaMachina avatar dimaMachina commented on September 29, 2024

Thx @eddyystop for creating a reference to my PR. You are right, after applying the changes to make work passing variables - I have an issue, and I don't have more ideas why this doesn't work, did I miss something?

from graphql.

dimaMachina avatar dimaMachina commented on September 29, 2024

I found where the problem comes from.
feathers-plus/graphql uses package https://github.com/eddyystop/graphql-resolvers-ast that currently not allow passing argumentValue.kind Variable

function getArgumentValue (argumentValue) {
  switch (argumentValue.kind) {
    case 'StringValue': // fall through
    case 'BooleanValue':
      return argumentValue.value;
    case 'IntValue':
      return parseInt(argumentValue.value, 10);
    case 'FloatValue':
      return parseFloat(argumentValue.value);
    case 'ListValue':
      return argumentValue.values.map(elem => getArgumentValue(elem));
    case 'ObjectValue':
      const obj = {};
      argumentValue.fields.forEach(field => {
        obj[field.name.value] = getArgumentValue(field.value);
      });
      return obj;
    default:
      throw new Error(`Unexpected GraphQL argument type "${argumentValue.kind}"`);
  }
}

I think this is a great feature to allow passing variables with query
Currently i have been implemented my solution to pass query object in variables.
This will helps us to avoid use convertArgsToParams function that replace __ to $

image

from graphql.

eddyystop avatar eddyystop commented on September 29, 2024

Thanks for the info.

from graphql.

mrfrase3 avatar mrfrase3 commented on September 29, 2024

Posting here for prosperity, but I do not recommend doing this but make sure you know what you're doing and remember to remove this when it is actually fixed.

  1. add the following to your scripts in package.json: "postinstall": "node src/util/variable-fix.js"
  2. create a new file at the directory: src/util/variable-fix.js
  3. add the following code to the file:
const fs = require('fs');

// eslint-disable-next-line no-console
console.log('Warning!! patching to inject variable support into deps');

const fGQL_dir = `${__dirname}/../../node_modules/@feathers-plus/graphql/lib/index.js`;
const gra_dir = `${__dirname}/../../node_modules/graphql-resolvers-ast/lib/index.js`;

let fGQL = fs.readFileSync(fGQL_dir, {encoding: 'utf8'});
let gra = fs.readFileSync(gra_dir, {encoding: 'utf8'});

fGQL = fGQL.replace('runQuery(query, params) {', 'runQuery(query, params, variables) {');
fGQL = fGQL.replace('graphql(this._schema, query, {}, content)', 'graphql(this._schema, query, {}, content, variables)');
fGQL = fGQL.replace('return this.runQuery(data.query, params);', 'return this.runQuery(data.query, params, data.variables);');
fGQL = fGQL.replace('return this.runQuery(params.query.query, params);', 'return this.runQuery(params.query.query, params, params.query.variables);');

gra = gra.replace('getArgumentValue(argument.value)', 'getArgumentValue(argument.value, ast)');
gra = gra.replace('function getArgumentValue (argumentValue) {', 'function getArgumentValue (argumentValue, ast) {');
gra = gra.replace('elem => getArgumentValue(elem)', 'elem => getArgumentValue(elem, ast)');
gra = gra.replace('getArgumentValue(field.value)', 'getArgumentValue(field.value, ast)');
gra = gra.replace(`
      return obj;
    default:`, `
      return obj;
    case 'Variable':
      return ast.variableValues[argumentValue.name.value];
    default:`);

fs.writeFileSync(fGQL_dir, fGQL);
fs.writeFileSync(gra_dir, gra);

When you run npm install, it will auto patch the node modules to give variable support. If you already have your node_modules installed, you can run npm run postinstall

Once again, not recommended and no warranty is given. This is only for if you needed variables implemented yesterday like me.

from graphql.

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.