Home

Awesome

graphql-to-karate πŸš€

Project Status: v0.2.0 release. The project is still in its early stages. To report a bug, feel free to open an issue.

Build Coverage

Version Downloads

Contributor Covenant Contributors Commits

Forks Stargazers Issues MIT License

LinkedIn

🎯 About The Project

Automagically generate Karate API tests from your GraphQL schemas. Useful for test-driven development, change validation in CI/CD, and more.

πŸ“’ Demonstration

https://user-images.githubusercontent.com/45316999/233819219-5149e02d-649f-4c3d-a3fd-844a231cf515.mp4

✨ Features

Here are some features that this tool provides:

See the full list of available options below for more information.

πŸ€– Installation

πŸ“₯ Binary Releases

Head over to releases and download the latest binary for your specific platform. If a binary for your platform is not available, see the Package Manager or Building From Source sections below.

πŸ“¦ Package Manager

graphql-to-karate is also available as a NuGet offering and can be installed with the following command:

dotnet tool install --global graphql-to-karate --version 0.2.0

πŸ› οΈ Building From Source

To build from source, clone the repository locally and run some flavor of the following command. Be sure to update <runtime identifier> to your target platform. A catalog of available runtime identifiers can be viewed here.

dotnet publish src/GraphQLToKarate.CommandLine/GraphQLToKarate.CommandLine.csproj \
  --configuration Release \
  --runtime <runtime identifier> \
  --output ./publish \
  --self-contained true \
  --force \
  /p:PublishReadyToRun=true \
  /p:PublishSingleFile=true \
  /p:TreatWarningsAsErrors=false

Once published, you can move the binary to your preferred install location to use.

🌌 Usage

To use graphql-to-karate, simply invoke the graphql-to-karate convert command, passing your GraphQL schema file as an argument:

graphql-to-karate convert my-schema.graphql

By default, you will be walked through conversion in an interactive way within the CLI.

A --non-interactive option as well as JSON configuration are also available (see full Command Options below), which may be useful in CI/CD environments.

πŸ“– Examples of Non-Interactive Invokation

Using Command-Line Options

graphql-to-karate convert my-schema.graphql \
  --non-interactive \
  --base-url "https://my-api.com" \
  --custom-scalar-mapping DateTime:string,Long:number,Float:number,URL:string \
  --query-operation-filter Users,UserById \
  --output-file some-api.feature\

Using a JSON configuration

graphql-to-karate convert my-schema.graphql --non-interactive --configuration-file config.json

This flavor of graphql-to-karate usage is used within CI/CD validation for this repository, where a mock GraphQL server is spun up, graphql-to-karate converts the GraphQL schema to a Karate API test, and then the generated Karate API test is run. The JSON configuration file used can be found here. Check out the full workflow here.

πŸ“ Convert Command Options

OPTIONDEFAULTABOUT
-h, --helpPrints help information
--log-levelInformationMinimum level for logging
--non-interactivefalseWhether to run conversion in a non-interactive way or not
--output-filegraphql.featureThe output file to write the Karate feature to
--query-nameQueryThe name of the GraphQL query type
--mutation-nameMutationThe name of the GraphQL mutation type
--exclude-queriesfalseWhether to exclude queries from the Karate feature or not
--include-mutationsfalseWhether to include mutations in the Karate feature or not
--base-url"https://your-awesome-api.com"The base URL to be used in the Karate feature
--custom-scalar-mappingThe path or raw value custom scalar mapping
--query-operation-filterA comma-separated list of GraphQL query operations to include in the Karate feature. If empty, all query operations will be included
--mutation-operation-filterA comma-separated list of GraphQL mutation operations to include in the Karate feature. If empty, all mutation operations will be included
--type-filterA comma-separated list of GraphQL types to include in the Karate feature. If empty, all types will be included
--configuration-fileThe path of the configuration file

πŸ—ΊοΈ Roadmap

See the open issues for a list of proposed features (and known issues).

🀝 Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated. For detailed contributing guidelines, please see the CONTRIBUTING docs.

πŸ“œ License

Distributed under the MIT License License. See LICENSE for more information.

Contact

@wbaldoumas

Project Link: https://github.com/wbaldoumas/graphql-to-karate

<!-- MARKDOWN LINKS & IMAGES --> <!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->