Can you append values to a GraphQL query?

Viewed 143

I am using GraphQL and Typeorm with an Oracle Db and I am trying to select all data within a particular table. The query executing is

SELECT "inventory"."id" AS "inventory_id", "inventory"."value" AS "inventory_value", "inventory"."description" AS "inventory_description" FROM "inventory" "inventory"

When it should be

SELECT "inventory"."id" AS "inventory_id", "inventory"."value" AS "inventory_value", "inventory"."description" AS "inventory_description" FROM "dbname.inventory"

The database "dbname", is through a Public Oracle Database Link.

Is there anyway for me to append "dbname." to the table portion of the GraphQL query or is there a better way to make the fix?

Attached is my model and resolver and please let me know if you have any questions/suggestions. Thanks in advance and let me know if there is anything that needs clarified.

// Inventory.ts
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm";
import { ObjectType, Field } from "type-graphql";

@Entity()
@ObjectType()
export class inventory extends BaseEntity {
  @PrimaryGeneratedColumn("uuid") id: number;

  @Field()
  @Column({ type: "varchar" })
  value: number;

  @Field()
  @Column({ type: "varchar" })
  description: string;
  
}
// InventoryResolver.ts
import { Resolver, Query } from "type-graphql";
import { inventory } from "../../models/Inventory";

@Resolver(inventory)
export class InventoryResolver {
  constructor() {}

  @Query(() => inventory, { nullable: true })
  async queryInventory() {
    return inventory.find();
  }
}
1 Answers

The issue is not related to to the type-graphql resolver. You just have to specify database name in the configuration of @Entity decorator. So according to typeorm decorator reference:

...
@Entity({
  name: "inventory"
  database: "dbname", // <-- 
})
@ObjectType()
export class inventory extends BaseEntity {
...
Related