A
A
Alexey P2018-08-08 20:09:07
Angular
Alexey P, 2018-08-08 20:09:07

How to form GraphQL queries with Input types?

Hello,
How to form GraphQL queries with Input types in Apollo Angular. Here's a code example:

addBlock(block: BlockData) {
  return this.apollo
    .mutate({
      mutation: gql`
        mutation Block {
          add (block: BlockInput!) {
            block
          }
        }
      `
  })
}

Where to declare the BlockInput type? In the same block, or is it possible somewhere in the configurations for all requests to register or declare a variable that contains this type and add it through interpolation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey P, 2018-08-09
@lynxp9

Did it like this:

addBlock(block: BlockContainer) {
  return this.apollo
  .mutate({
    mutation: gql`
      mutation Block($blockContainer: BlockDataInput!) {
        add (blockData: $blockContainer) {
          id
          type
          data
          order
        }
      }
    `,
    variables: {
      blockContainer: block
    }
  })
  .map((d) => d.data.add);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question