Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where clause not working with graphql: "15.0.0" #405

Closed
zacksayenko opened this issue Apr 28, 2020 · 11 comments
Closed

Where clause not working with graphql: "15.0.0" #405

zacksayenko opened this issue Apr 28, 2020 · 11 comments
Assignees

Comments

@zacksayenko
Copy link

I was just setting up a new project and noticed that using "graphql": "^15.0.0" didn't work well with the latest join-monster package.

Main issue that I noticed is that where clause wasn't honored.

Here are the packages that I was using:

  "dependencies": {
    "express": "^4.17.1",
    "express-graphql": "^0.9.0",
    "graphql": "^15.0.0",
    "join-monster": "^2.1.0",
    "knex": "^0.21.1",
    "pg": "^8.0.3"
  }

Relevant parts of the code:

const Account = new graphql.GraphQLObjectType({
    name: 'Account',
    fields: () => ({
      id: { type: graphql.GraphQLString },
      name: { type: graphql.GraphQLString },
      email: { type: graphql.GraphQLString },
    }),
  });
  
  Account._typeConfig = {
    sqlTable: 'account',
    uniqueKey: 'id',
  }

const QueryRoot = new graphql.GraphQLObjectType({
    name: 'Query',
    fields: () => ({
      hello: {
        type: graphql.GraphQLString,
        resolve: () => "Health check successful!"
      },
      account: {
        type: Account,
        args: { 
            id: { type: graphql.GraphQLNonNull(graphql.GraphQLString) } 
        },
        where: (accountTable, args, context) => {
            return `${accountTable}.id = '${args.id}'`
        },
        resolve: (parent, args, context, resolveInfo) => {
          return joinMonster.default(resolveInfo, {}, sql => {
            console.log(sql);
            return knex.raw(sql);
          });
        }
      },
    })
  });
  
  const connectedSchema = new graphql.GraphQLSchema({
    query: QueryRoot,
  });

When using graphql 15, the sql statement that was produced inside the resolver didn't have the where clause.
As soon as I downgraded to 14.1.1 all worked fine.

@Auronmatrix
Copy link

+1. Can confirm this. Where clause is ignored in graphql 15.0.0

@JCMais
Copy link

JCMais commented Jul 17, 2020

This library needs to be changed to use the extensions object instead of adding new fields directly to the GraphQL definitions.

The extensions field was added here graphql/graphql-js#2097

@alexbbt
Copy link
Contributor

alexbbt commented Jul 17, 2020

This is already being worked on here: #418

@lorensr
Copy link
Member

lorensr commented Aug 11, 2020

Published 3.0.0-alpha.1. @zacksayenko let me know if it works for you with graphql@15! Note the new where format: https://join-monster.readthedocs.io/en/latest/where/

@lorensr lorensr self-assigned this Aug 11, 2020
@mnunezdm
Copy link

mnunezdm commented Nov 4, 2020

when is this version going to be released? ive been using it since august with no issues

@lorensr
Copy link
Member

lorensr commented Nov 4, 2020

Where clause should work in the v3 beta. Let us know if you have problems with it!

@bwind00
Copy link

bwind00 commented Nov 12, 2020

How do I get v3 beta? We have an urgent need to get this working, join-monster with the latest graphql. Thanks!

@lorensr
Copy link
Member

lorensr commented Nov 12, 2020 via email

@bwind00
Copy link

bwind00 commented Nov 12, 2020

thanks, but that just installed 3.0.0-alpha2 which has the same problem with where mentioned above

@bwind00
Copy link

bwind00 commented Nov 13, 2020

Sorry, an ingenious colleague figured out what we were doing wrong. In case it helps others, we had forgotten to encapsulate the where attribute in the new extensions attribute...
extensions: {
joinMonster: {
where: (att, args, context) => {
return ${att}."ATRBT_ID" = :atrbtId
}
}
}

@lorensr
Copy link
Member

lorensr commented Nov 14, 2020

Glad to hear! And just released as v3.0.0

@lorensr lorensr closed this as completed Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants