GithubHelp home page GithubHelp logo

vizgql's Introduction

Vizgql.Console

Vizgql.Console is a command-line interface tool designed for parsing GraphQL SDL documents. It provides an overview of fields and their associated authorization directives, along with listing different roles/policies the directives may have.

Features

  • Parse GraphQL SDL documents from a file or URL.
  • Display fields with authorization directives.
  • List roles and policies linked to the authorization directives.
  • Highlight validation errors and unique constraints in the schema.

Installation

dotnet tool install Vizgql.Console --global

Usage

To use Vizgql.Console, execute the following commands with the appropriate options:

vizgql -f [path_to_file]
vizgql -u [URL]

Options

  • -f, --file: Path to the file to be parsed.
  • -u, --url: URL from which text will be downloaded for parsing.
  • -n, --header-name: HTTP header name for authentication (Default: Authorization).
  • -t, --header-token: HTTP header token for authentication.
  • -p, --policies: Comma-separated list of policies to apply to the schema.
  • -r, --roles: Comma-separated list of roles to apply to the schema.
  • --validations: Print out any validation errors (Default: false).
  • --unique-constraints: Prints all the unique constraints as a comma-separated list.
  • --format: Ansi, Html, Csv
  • --help: Display help screen.
  • --version: Display version information.

Example

PS C:\Users\User> vizgql -u https://hotchocolateschema.com/graphql?sdl --validations --unique-constraints

Output when downloading sdl from a URL. Using the validations and unique-constraints option.

Formats

You can output in several formats

Ansi

Default format, for cli usage. Supports validations, unique-constraints, roles and policy filter.

Html

Outputs HTML. Supports validations and unique-constraints.

Csv

Outputs CSV, only list the fields and constraints.

In unit tests.

dotnet add package Vizgql.Core

[Test]

    private readonly ValidationAssertion[] _allowedAssertions =
    [
        new("Mutation", MissingAuthorizationConstraints),
        new("Query", MissingAuthorizationConstraints),
        new("Subscription.priceChange", MissingFieldAuthorization)
    ];
    
    public async Task SchemaChangedAsync()
    {
        var schema = await GraphQLTestService.GetSchema();
        var schemaType = SchemaParser.Parse(schema.ToString());

        var validations = schemaType.Validate().ToArray();

        foreach (var validation in validations)
        {
            Assert.That(_allowedAssertions, Does.Contain(validation));
        }

        Assert.That(validations, Has.Length.EqualTo(_allowedAssertions.Length));
    }

Above is a example setup for unit test for C#. GraphQLTestService is setup for the HotChocolate GraphQL API. GetSchema returns the ISchema for the API. We can get validations from the parsed SchemaType with the Validations() method. You can assert that it should be empty, or make exceptions for known assertions like in the example above. Not all validation errors are necessary to fix for a secure schema, as authorizations are inherited.

vizgql's People

Contributors

downgoat avatar dependabot[bot] avatar

Stargazers

 avatar Endre Medhus Mæland avatar Espen Hatleskog avatar Silje Hetland avatar Lars Antonio Kay avatar Sander Struijk avatar

Watchers

 avatar

vizgql's Issues

color output

Color the output to better vizualize and highlight issues. I overlooked that the user did not have access to any mutations when using a role filter because the text was hidden among all the other. Maybe think about other ways to present the data as well,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.