Logo

dev-resources.site

for different kinds of informations.

Trace-Based Tests with GraphQL in Action!

Published at
9/10/2024
Categories
graphql
testing
opentelemetry
monitoring
Author
adnanrahic
Author
10 person written this
adnanrahic
open
Trace-Based Tests with GraphQL in Action!

Trace-based Tests with GraphQL in Action 💣

Join us for the GraphQL and Playwright test trigger webinar on September 11th!

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. It offers a clear, comprehensive description of your API's data, allowing clients to request exactly what they need—nothing more, nothing less. This approach simplifies API evolution and enables powerful developer tools.

Wouldn't it be great if Tracetest had a GraphQL trigger for testing GraphQL APIs?

Our community certainly thinks so. In fact, three community members have requested this feature in recent months.

Introducing the Tracetest GraphQL Trigger 🔥

Great news! The team has just released a brand-new GraphQL trigger type.

Join our demo environment to try it yourself!
Or, check out the guided example to run it in your own environment.

You can now effortlessly test GraphQL APIs using OpenTelemetry and trace-based testing. This feature is a natural addition to your existing HTTP and gRPC API tests.

This update enables you to run tests using GraphQL queries, expanding your API testing capabilities.

You have two options: upload your own schema or use schema introspection. With the latter, Tracetest automatically fetches the schema from your API URL.

From here, you can create test specs just as you would with other triggers. To streamline the creation and execution process and take advantage of any supported integrations. Navigate to the Automate tab to download or copy the definition file and the trigger script.

Testing GraphQL APIs

Running trace-based tests against GraphQL APIs has never been simpler. With this new trigger you can finally get the same test coverage for your GraphQL APIs as for your existing HTTP and gRPC APIs.

There are 4 steps to create and run a GraphQL trigger test:

  1. Create a test with the GraphQL trigger 🕵️
  2. Add your GraphQL API endpoint 🔗
  3. Use the GraphQL Schema Introspection 🔍
  4. Add a GraphQL query ❓
  5. Hit run 🏃
  6. Add test specs 🧪
  7. Profit 🤑

Let me walk you through it all step-by-step.

To run a test with the GraphQL trigger, click the GraphQL trigger type when creating a new test.

Add your GraphQL API endpoint. Let’s use the Pokeshop demo as a sample.

https://demo-pokeshop.tracetest.io/graphql
Enter fullscreen mode Exit fullscreen mode

Click the Use GraphQL Introspection button on the Schema tab to load the GraphQL schema.

Go back to the Query tab. Let’s add a mutation with two fields.

mutation create {
  createPokemon(name: "Charizard", type: "flying", isFeatured: false, imageUrl: "https://img.pokemondb.net/artwork/large/charizard.jpg") {
    id
    name
    isFeatured
    type
    imageUrl
  }

  importPokemon(id: 38) {
    id
  }
}
Enter fullscreen mode Exit fullscreen mode

This will trigger the test and show you a trace response to start building test specs. The kicker here is that the two fields in the mutation will show two flows in the trace response.

You can see both the create and import flow in the trace.

To validate the GraphQL API, you can create a test spec like this:

- selector: span[tracetest.span.type="http" name="POST /graphql" http.method="POST"]
  name: Validate route is "/graphql" and data is valid.
  assertions:
    - attr:http.route   =   "/graphql"
    - attr:http.response.body =
      '{"data":{"createPokemon":{"id":224318,"name":"Charizard","isFeatured":false,"type":"flying","imageUrl":"https://img.pokemondb.net/artwork/large/charizard.jpg"},"importPokemon":{"id":38}}}'
Enter fullscreen mode Exit fullscreen mode

You can also create specific test specs for the async flows in the Pokeshop demo like validating the RabbitMQ queue and the async API triggered behind the RabbitMQ queue.

But, what’s more exciting is that you can validate database interactions. In this sample you can validate both the import and create database calls in the same test. Here’s the validation for the create flow.

And, by selecting the database span below the RabbitMQ queue, you can validate the import flow as well.

Just like that, in a few minutes, you’ve created a GraphQL API test that validates two flows with multiple database interactions, async APIs and a message queue. If that isn’t magic, I don’t know what it. 🪄

GraphQL API Trigger with the Playwright Engine and Test Observability

With Tracetest, you can use the new GraphQL trigger alongside any other feature. Whether you want Tests as part of a Test Suite, plan to use them with the Synthetic Monitor Framework, or aim to include them in GitHub Actions—it's all possible.

A game-changing feature would be combining tests using both the GraphQL trigger and Playwright engine trigger into a Run Group. Then, add these to a Synthetic Monitor and run them on a schedule to continuously validate your applications in real time!

Try This in Tracetest yourself!

Check out the GraphQL trigger documentation to get started with your own tests. We're eager to hear your thoughts on this first version of the GraphQL Trigger!

Last, but not least, do you want to learn more about Tracetest and what it brings to the table? Check the docs and try it out by signing up today!

Also, please feel free to join our Slack community, give Tracetest a star on GitHub, or schedule a time to chat 1:1.

opentelemetry Article's
30 articles in total
Favicon
OpenTelemetry Collector Implementation Guide: Unified Observability for Modern Systems
Favicon
Auto-Instrumentação com OpenTelemetry no EKS [Lab Session]
Favicon
InsightfulAI v0.3.0a1 Update: Railway Oriented Programming and Enhanced OpenTelemetry for Robust Pipelines
Favicon
Using OpenTelemetry with gRPC in Node.js and Express Hybrid Applications
Favicon
Enhancing Observability in Machine Learning with OpenTelemetry: InsightfulAI Update
Favicon
From Zero to Observability: Your first steps sending OpenTelemetry data to an Observability backend
Favicon
Usando stack de monitoria opensource no Kubernetes (sem Prometheus)
Favicon
Observing Spin Apps with OpenTelemetry and the .NET Aspire Dashboard
Favicon
Golang com Opentelemetry, prometheus, Grafana tempo OSS e Grafana padrão
Favicon
Monitor R Applications with an OpenTelemetry Collector
Favicon
Understanding Open telemetry and Observability for SRE
Favicon
How to publish JetBrains Rider plugin for opentelemetry/honeycomb
Favicon
Tracetest Tip: Testing Span Order with Assertions
Favicon
How to publish JetBrains Rider plugin for opentelemetry/honeycomb
Favicon
Monitoring Browser Applications with OpenTelemetry
Favicon
Instrumentação com OpenTelemetry: Zero-Code, Code-Based ou Bibliotecas Instrumentadas?
Favicon
OpenTelemetry: Traces, Métricas, Logs e Baggage
Favicon
Getting Started with OpenTelemetry
Favicon
Explorando a Observabilidade com OpenTelemetry: Propagação de Contexto e Arquiteturas Distribuídas
Favicon
Observability with ASP.NET Core using OpenTelemetry, Prometheus and Grafana
Favicon
Trace-Based Tests with GraphQL in Action!
Favicon
Wednesday Links - Edition 2024-08-07
Favicon
Implementing an Order Processing System: Part 5 - Distributed Tracing and Logging
Favicon
Tracetest Monitors: Synthetic Monitoring with OpenTelemetry and Playwright
Favicon
Unlocking Open Source Observability: OpenTelemetry, Prometheus, Thanos, Grafana, Jaeger, and OpenSearch
Favicon
Announcing Tracetest Enterprise On-Prem Solution
Favicon
OpenTelemetry with Elastic Observability
Favicon
Performans Ve Güvenilirlik Ölçekleri
Favicon
OpenTelemetry Metrics meets Azure
Favicon
OpenTelemetry Tracing on Spring Boot, Java Agent vs. Micrometer Tracing

Featured ones: