1

How can I perform the following SQL Insert Query as a GraphQL Mutation Insert?

INSERT INTO User (id, name, user_type_id)
VALUES
(1, "Name", (SELECT id FROM UserType WHERE user_type="Guest"))

Provided that there is a One to Many relation from UserType table (id column) to User table (user_type_id column).

gzone
  • 31
  • 7
  • do you use a mapper like sequelize in your code or do you write raw queries. Also, graphql only transports the data to your server. – Gh05d Aug 30 '19 at 12:37
  • 1
    What I have is raw queries with payloads and send them for execution at the GraphQL endpoint. We already have a couple of Mutation Inserts, Upserts in our code. But, all of these GraphQL queries was for inserting to a specific table. But, what we are trying to achieve is to have a foreign key inserted in `User` table by using a where condition in `UserType` table. This works like a charm in an SQL query. But, unable to find any help on getting this work as a GraphQL insert. – gzone Aug 30 '19 at 12:44

1 Answers1

0

You should checkout an ORM that work with your technology. like 'sequelize' for example.

Itay Golan
  • 33
  • 8