#How do I create a model where a field requires input to be generated

1 messages · Page 1 of 1 (latest)

split mauve
#

I would like to model an object where the client supplies input that is used to generate part of the model. The generation needs to coordinate with a 3rd party service so I assume I would need to connect this to a lambda.

Would I have to null out the mutations and attach a function directive

type Double @model(queries: null, mutations: null, subscriptions: null) @auth(rules: [{allow: owner}]) {
id: ID!
value(input: Float!): Float @function(name: "exchangeValue-${env}")
}

Or would I leave only the create mutation and somehow link that to a lambda?

type Double @model(queries: null, mutations: {create: "createDouble"}, subscriptions: null) @auth(rules: [{allow: owner}]) {
id: ID!
value(input: Float!): Float
}

Or is this not possible with the @model directive.

split mauve
#

The client should also not be ablet to supply value directly and instead they must submit input for value to be generated.

carmine axle
#
type Double @model(queries: null, subscriptions: null) @auth(rules: [{ allow: owner, operations: [read] }, { allow: private, provider: iam }]) {
  # ...
}
#
type Mutation {
  createMySpecialDoubleModel(input: MyInput): Double @function(name: "...")
}
zenith siren
#

When using this technique, beware that function lambda needs to return in 30 seconds or API Gateway timeout. Since there is a 3rd party API request/response involved, you may want to do the above but stuff the user input into DB/SQS and return quickly,. Then trigger the rest of the job and return response via subscription to the record-id you get back from the call.