1) Can I do this without the where and id? 2) Are ...
# orm-help
i
1) Can I do this without the where and id? 2) Are the create and update correct?
Copy code
mutation upsertMarket(
  $trader: String!,
  $base: String!,
  $quote: String!,
  $category: String!,
  $type: String!
) {
  upsertMarket(
    where: {
      id: "123"
    },
    create: {
      trader: $trader
      base: $base
      quote: $quote
      category: $category
      type: $type
    },
    update: {
      trader: $trader
      base: $base
      quote: $quote
      category: $category
      type: $type
    }
  )
}
I got it with
Copy code
mutation upsertMarket(
  $trader: String!,
  $base: String!,
  $quote: String!,
  $category: String!,
  $type: String!
) {
  upsertMarket(
    where: {
      id: ""
    },
    create: {
    	trader: $trader
      base: $base
      quote: $quote
      category: $category
      type: $type
  	},
    update: {
      trader: $trader
      base: $base
      quote: $quote
      category: $category
      type: $type
    }
  )
  {
    id
  }
}
But this creates a new entry in the DB every time because I do not supply the ID (or a nonexistant one)
I'm running this query from an
Importer
process that runs every 24 hours, so I do not know the ID's.
There also might be new entries, some removed and others get disabled: true, etc.
m
you can supply any unique field in the where argument.
What’s your usecase? When should the update part be executed and when the create part?
i
I'm importing the list of markets from many traders through their API's through a client interface (CCXT). I want to update this list every 24 hours so all the new reponses should be regarded as truth. Before Prisma I didn't have ID's in the tables but now that I do I see the problem; How do I know which existing items to remove (disabled: true)?
I guess query first and if empty then just insert otherwise compare and disable the ones not in the new API response and update the rest?
h
try to find something that's unique about them
maybe
$trader
?
i
I tried
trader: $trader
but that causes an error
(in the where clause)
m
There has to be a unique identifier for a market. If not you could delete all markets before import but that does not sound useful to me. 🤷