Can GraphQL Mutation API handle custom type params...
# support
b
Currently, we're running into the issue of passing a ton of properties into our GraphQL mutations that are of type
String!
is it possible for us to get support for passing custom types in the GraphQL params This would greatly help simplify queries in client-side code.
r
Hi @boogiecoco. , just so I understand, do you have an example of a mutation you're doing right now, and how it would ideall look with custom types?
b
Here's one example at the top of my head where it could be useful: export const CREATE_COMMUNICATION = gql` mutation CreateCommunication( $payload: [CommunicationPayloadInput!]! ) { createCommunication( communication: { resourceType: "Communication" payload: $payload } ) { id } } `
As opposed to: export const CREATE_COMMUNICATION = gql
Copy code
mutation CreateCommunication(
  $payloadContentString: String!
  $payloadContentAttachmentTitle: String!
  $payloadContentAttachmentUrl: String!
) {
  createCommunication(
    communication: {
      resourceType: "Communication"
      payload: [
        {
          contentString: $payloadContentString,
          contentAttachment: {
            title: $payloadContentAttachmentTitle,
            url: $payloadContentAttachmentUrl
          }
        }
      ]
    }
  )
r
@boogiecoco. Good news! I think I have a solution for you.
So you can't define custom types on the client, since the server maintains the GQL introspection schema. The good news is that Medplum generates GraphQL types not just for the top-level resource types, but also for the complex inner types (AKA "backbone elements")
I just tested this query on graphiql.medplum.com
Copy code
mutation CreatComm($payload: [CommunicationPayloadCreate!]!) {
  CommunicationCreate(res: {
    resourceType: "Communication",
    status: "draft",
    payload: $payload
  }) {
    id,
    resourceType, 
    payload {contentString, contentAttachment {url}}
  }
}
The type name for the parameter would be
<inner-type-name>Create
b
That works for us, thank you !
156 Views