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

Join monster is not returning all the requested in the sql string it generates when using it with Apollo server 2.0. #20

Open
abhirham opened this issue Mar 26, 2020 · 1 comment

Comments

@abhirham
Copy link

Below is my app.js.

const express = require('express');
const app = express();
const {ApolloServer} = require('apollo-server-express');

const server = new ApolloServer({schema});
server.applyMiddleware({app, path: '/graphql'});

app.listen(4000,()=>console.log(`server started on port $4000}`));

Here is my schema:

const typeDefs = `

    input CustomersInput {
        EMAIL_ADDRESS: String
        NAME: String
        HOME_PHONE: String
        SPA_FOLIO_ID: ID
        ALL_CUSTOMER_ID: ID
    }

    type Customer {
        ALL_CUSTOMER_ID: ID
        NAME: String
        ALL_CUSTOMER_TYPE: String
        FIRST_NAME: String
    }

    type Query {
        customers(input: CustomersInput): [Customer]!
    }

    schema {
        query: Query
    }
`;

const resolvers = {
    Query: {
        customers(parent, args, ctx, resolveInfo) {
            return joinMonster.default(resolveInfo,ctx, async sql=>{
                console.log(sql)
                return knex.raw(sql); 
            });
        },
    },
}

const schema = makeExecutableSchema({
    typeDefs,
    resolvers,
});

joinMonsterAdapt(schema, {
    Query: {
        fields: {
            customers: {
                where: (customerTable,args) => {
                    return escape(`${customerTable}.UPPER_FIRST_NAME || ' ' || ${customerTable}.UPPER_LAST_NAME || ' ' || ${customerTable}.UPPER_FIRST_NAME like %L`, `%${args.input.NAME.toUpperCase()}%`);
                },
            },
        }
    },
    Customer: {
        sqlTable: 'ALL_CUSTOMER',
        uniqueKey: 'ALL_CUSTOMER_ID',
    },
});



module.exports = schema;

Here is the query:

{
  customers(input:{NAME: "as"}){
    FIRST_NAME
    ALL_CUSTOMER_ID

  }
}

Here is the sql generated by joinmonster:

SELECT
  "customers"."ALL_CUSTOMER_ID" AS "ALL_CUSTOMER_ID"
FROM ALL_CUSTOMER "customers"
WHERE "customers".UPPER_FIRST_NAME || ' ' || "customers".UPPER_LAST_NAME || ' ' || "customers".UPPER_FIRST_NAME like '%AS%'

As you can see, I am requesting for FIRST_NAME , but joinmonster is not including it in the generated sql.

This is not the case when I use express-graphql . It works fine.
Here is the link to my stackOverflow with all the details: https://stackoverflow.com/q/60868650/6425689

@bcloutier
Copy link

bcloutier commented May 28, 2020

@abhirham I was having the same issue after I upgraded to Apollo Server 2.0. In order to fix it I had to add an explicit mapping from graphql field to sql column. Example:

{  
...
Customer: {
        sqlTable: 'ALL_CUSTOMER',
        uniqueKey: 'ALL_CUSTOMER_ID',
        fields: { 
                firstName: { sqlColumn: 'first_name' }
        }
    },
}

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

2 participants