0
votes

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).

1
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
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

1 Answers

0
votes

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