Having trouble getting Apollo Server 2.0 to function properly with the join-monster-graphql-tools-adapter when using an Oracle

In the process of creating a graphql server using expressjs, I have implemented the following code snippet:

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}`));

This is the schema definition that I am working with:

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;

Upon running the application and accessing http://localhost:4000/graphql, along with executing the provided query:

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

  }
}

The resulting data looks like this:

{
  "data": {
    "customers": [
      {
        "FIRST_NAME": null,
        "ALL_CUSTOMER_ID": "563",
      },
    ]
  }
}

However, after inspecting the generated SQL query by joinmonster, it appears to only fetch the customer id without any additional fields requested, as shown below:

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%'

When switching to use express-graphql instead of ApolloServer, the generated query retrieves all the necessary fields as expected:

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

It seems to work smoothly with express-graphql. Is there something I might be overlooking?

Answer №1

Has a resolution been found for this issue? I've encountered a similar situation where null values are being returned, except for the id in my types. Initially, when using express-graphql, everything functioned as expected. However, upon switching to ApolloServer from apollo-server-express, it appears that while the schema loads correctly and displays in the GraphQL playground, the SQL queries do not execute properly, resulting in widespread null values.

In the upcoming version of join-monster (3.0, unreleased), there has been a shift of all join-monster specific syntax into the extensions property. This adjustment may potentially resolve the issue if it is the additional non-standard GraphQL properties affecting the functionality.

const User = new GraphQLObjectType({
  name: 'User',
  extensions: {
    joinMonster: {
      sqlTable: 'accounts', // The SQL table assigned to this object type is named "accounts"
      uniqueKey: 'id' // Each row has a unique id
    }
  },
  fields: () => ({
    /*...*/
  })
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A step-by-step guide on converting SVG to PNG format with canvg.js and Canvas

We are attempting to convert an SVG image to PNG using canvg.js, but upon clicking the button labeled "Take a screenshot", an error is displayed in the console stating "vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in v-on handler: "Ref ...

Issue with parent-child communication in React.js causing malfunction

I am facing an issue with maintaining state between two different JavaScript files using React. The parent class, break.js, is defined as follows: export default function AlertDialog(props) { const [demoOpen, setDemoOpen] = React.useState(true); ...

How to transition from using a CDN to NPM for implementing the Google Maps JavaScript MarkerClusterer?

Currently integrating Google Maps JavaScript MarkerClusterer from CDN, I am considering transitioning to the NPM version for Typescript checking in my JavaScript files. However, I am encountering difficulties understanding how to make this switch. The docu ...

Encountering an 'undefined' error when rendering data in Vue.js

For some reason, I am facing an issue with rendering data stored in a JSON object. It seems to work perfectly fine when written in plain JavaScript, but when I convert it to Vue, it fails to work. I even tried reverting back to an older commit to see if th ...

What is the best way to choose all cells that begin, include, or finish with a specific term using JQuery/CSS?

I have a table with some cells and I am looking to utilize JQuery to select specific cells. For example: <td>John Doe</td> <td>John Doe1</td> <td>1John Doe</td> I want to select cells that start with 1, include Doe, a ...

Obtain the value from the controller of the amazing-rating component

Currently utilizing the amazing Rating AngularJS library available at https://github.com/bandraszyk/awesome-rating I am interested in understanding how to retrieve the selected value and store it in my controller. The $scope.rating is returning undefined ...

Function not being triggered by button

We are struggling to get a button to trigger a function upon being clicked. Is there a reason why the function is not being called? <body> <button onclick="instagramclick()">Login to instagram</button> <button onclick="myFunction( ...

Struggling with passing a function along with parameters to a component in React has been a challenge for me

Currently utilizing React in conjunction with NextJS My goal is to send a function, along with its parameters, to my 'Alerts' component so that it can wait for user input before executing the function. For instance, prior to clearing a list, I ...

Error encountered while compiling React application: Module build unsuccessful due to failure in ./node_modules/babel-loader/lib/index.js

Having an issue while trying to compile a React app. After pulling the repo from Github, running yarn install, and then compiling it, I encountered the following error: Module build failed (from ./node_modules/babel-loader/lib/index.js) SyntaxError: {file_ ...

Unable to trap error using try-catch block within an asynchronous function

I'm attempting to integrate a try-catch block into an async function, but I am having trouble catching errors with status code 400 using the code below. const run = async () => { const response = await client.lists.addListMember(listId, { ema ...

Speeding up the loading time of my background images

body { background: url(http://leona-anderson.com/wp-content/uploads/2014/10/finalbackgroundMain.png) fixed; background-size:100% auto; } I have unique background images on each of my sites, but they are large in size and take some time to load due to bein ...

Oops! Looks like the 'opennebula' module is missing in your Meteor.JS project

I've attempted using meteorhacks:npm but encountered the same issues. While working on a Meteor.JS application with iron:router installed, I'm facing difficulties loading the NPM module "opennebula" (found at https://github.com/OpenNebula/addon- ...

Compilation failed: Unable to parse due to an unexpected token, ";" expected

I'm encountering an error in my component class after creating a constructor: Component class with constructor: import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; constructor(p ...

Unlocking the Power of Combining JMVC and Server-side MVC Models

It's been a few days since I posted this question here and still no response. I also tried posting it on forum.javascriptMVC.com and finally got an answer, but I'm looking for more insights. Here's my question: After reading the documentat ...

Error: The Vuex store is not defined in the Vue.js component when attempting to access it using

I've recently set up a new vue-cli webpack project with Vuex. I have initialized my Vuex store in store.js like so: import Vue from "vue"; import Vuex from "vuex"; Vue.use(Vuex); const store = new Vuex.Store({ state: {} }); export default store; ...

Incorporate a new visual element with a texture in three.js

I'm struggling to apply a texture to a mesh and keep getting this error message: [.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1 It's frustrating not understanding ...

Import a JSON file into Parse by reading and parsing it to store in the database

I am currently facing a challenge with parsing JSON data in my Parse Cloud function. After fetching the JSON file, I need to parse the data and populate one of my classes with the results. However, I'm having trouble figuring out how to properly parse ...

Is there a way to modify the Java class name to consist of two separate words?

(Edited) I am completely new to android app development. My question is: How can I rename a java class with two words instead of one? My main menu consists of 3 options, each linked to a java class: public class Menu extends ListActivity{ String cla ...

Struggle with registering fonts in Canvas using JavaScript

I've been struggling to add a custom font to my canvas for hosting the bot. Even though I'm not encountering any errors, the font fails to display on the host. Below is the code snippet: const { AttachmentBuilder } = require('discord.js&apos ...

Understanding Three.js Fundamentals: Resolving GLTFLoader Animation and Variable Not Found Issues

My understanding of JS is very basic. After exploring the three.js docs on Loading 3D models, I managed to successfully render a 3D object and center it: const loader = new GLTFLoader(); loader.load( 'Duck.gltf', function ( duck ) { con ...