UniversalDataGraph and mutations

Hi!

I’m currently exploring Tyk as a manager for existing Rest apis.

Its UniversalDataGraph is working very well and has been setup quickly for reading data.

Yet I’m missing documentation on how to implements mutations to dispatch writing to APIs from GQL.

Can you point me to some code or example on the best way to accomplish this?

Thank you!

Hey @Solido,

have you checked out these pages 3. Mutations ? There’s a short video where Jay explains how it can be done and also some code snippets below to help you replicate.
In case you run into problems, just reach out.

Welcome to the community!

1 Like

Thank you for the quick reply @agata-wit

I hoped on the train when the feature was released and skipped this part while concentrating on building from the video. Thanks for the link it is what I was looking for.

Do you happen to have a preconfigured .json conf to share with demo api that I could just setup in my side to have this up and running to continue my exploration of the solution?

Regards

I can put something together quickly. Would it be enough if I get you the “graphql” node of the json only? This is where the whole UDG config sits, rest of it is A LOT of API settings, which I am sure you know by now.

Thank you Agata,

I was just asking for something already existing but I can setup it up myself.
That says for new comers having something like this available that bind to a public Rest API would be a nice demonstration and fast setup. Maybe consider the idea.

Thank you very much @agata-wit
Best Regards,
Robert

It’s in the works!
In the meantime though, in the interest of getting you closer to your goal, here’s a config for mutation:

"graphql": {
      "schema": "type Mutation {\n  addReview(text: String, userId: String): Review\n  deletReview(reviewId: String): String\n}\n\ntype Query {\n  user(id: String): User\n}\n\ntype Review {\n  id: String\n  text: String\n  userId: String\n  user: User\n}\n\ntype User {\n  id: String\n  username: String\n  reviews: [Review]\n}",
      "enabled": true,
      "engine": {
        "field_configs": [
          {
            "type_name": "Mutation",
            "field_name": "addReview",
            "disable_default_mapping": true,
            "path": [
              ""
            ]
          },
          {
            "type_name": "Mutation",
            "field_name": "deletReview",
            "disable_default_mapping": false,
            "path": [
              "message"
            ]
          }
        ],
        "data_sources": [
          {
            "kind": "REST",
            "name": "addReview",
            "internal": false,
            "root_fields": [
              {
                "type": "Mutation",
                "fields": [
                  "addReview"
                ]
              }
            ],
            "config": {
              "url": "http://localhost:4001/reviews",
              "method": "POST",
              "body": "{\n    \"text\": \"{{.arguments.text}}\",\n    \"userId\": \"{{.arguments.userId}}\"\n}",
              "headers": {},
              "default_type_name": "Review"
            }
          },
          {
            "kind": "REST",
            "name": "deleteReview",
            "internal": false,
            "root_fields": [
              {
                "type": "Mutation",
                "fields": [
                  "deletReview"
                ]
              }
            ],
            "config": {
              "url": "http://localhost:4001/reviews/{{.arguments.reviewId}}",
              "method": "DELETE",
              "body": "",
              "headers": {},
              "default_type_name": "String"
            }
          }
        ]
      },
      "type_field_configurations": [],
      "execution_mode": "executionEngine",
      "proxy": {
        "auth_headers": {}
      },
      "subgraph": {
        "sdl": ""
      },
      "supergraph": {
        "subgraphs": [],
        "merged_sdl": "",
        "global_headers": {},
        "disable_query_batching": false
      },
      "version": "2",
      "playground": {
        "enabled": false,
        "path": ""
      },
      "last_schema_update": "2022-05-18T17:59:27.029+02:00"
    }```
1 Like

Much appreciated @agata-wit !