22 stable releases

new 3.7.1 May 14, 2024
3.7.0 Apr 28, 2024
3.5.0 Mar 25, 2024
3.4.3 Jan 22, 2024
3.0.0-beta.3 May 13, 2023

#503 in HTTP server

Download history 2873/week @ 2024-01-25 3163/week @ 2024-02-01 3251/week @ 2024-02-08 2850/week @ 2024-02-15 1901/week @ 2024-02-22 2089/week @ 2024-02-29 3093/week @ 2024-03-07 3091/week @ 2024-03-14 2544/week @ 2024-03-21 2900/week @ 2024-03-28 3179/week @ 2024-04-04 3124/week @ 2024-04-11 3840/week @ 2024-04-18 2539/week @ 2024-04-25 3062/week @ 2024-05-02 1711/week @ 2024-05-09

11,717 downloads per month
Used in cynic-cli

MPL-2.0 license

555KB
13K SLoC

Cynic Introspection

cynic-introspection defines a GraphQL introspection query that can be run using cynic, a rust GraphQL client

This can be used for any reason you'd want to introspect a GraphQL server - including when you're using cynic as a library in your own project.

Features

  • Support for introspecting servers that support both GraphQL 2021 and GraphQL 2018.
  • Contains a capability detection query that can determine which version of the GraphQL specification a server supports prior to querying it.

Usage

See the documentation on docs.rs for instructions on using cynic-introspection.


lib.rs:

cynic-introspection defines a GraphQL introspection query that can be run using cynic, a rust GraphQL client.

This can be used for any reason you'd want to introspect a GraphQL server - including when you're using cynic as a library in your own project.

It also provides a [Schema] abstraction on top of the introspection query results, which provides some stronger typing than using the introspection results directly.

use cynic::{QueryBuilder, http::ReqwestBlockingExt};
use cynic_introspection::IntrospectionQuery;

// We can run an introspection query and unwrap the data contained within
let introspection_data = reqwest::blocking::Client::new()
    .post("https://swapi-graphql.netlify.app/.netlify/functions/index")
    .run_graphql(IntrospectionQuery::build(()))
    .unwrap()
    .data
    .unwrap();

// And then convert it into a schema for easier use.
let schema = introspection_data.into_schema().unwrap();

assert_eq!(schema.query_type, "Root");

GraphQL Versions

GraphQL servers currently commonly support two different versions of the GraphQL specification:

The fields available for introspection differ between these two versions. By default we query only for fields supported in the June 2018 specification. You can request a different version of the query using InstrospectionQuery::with_capabilities:

use cynic::http::ReqwestBlockingExt;
use cynic_introspection::{IntrospectionQuery, SpecificationVersion};

// We can run an introspection query and unwrap the data contained within
let introspection_data = reqwest::blocking::Client::new()
    .post("https://spacex-production.up.railway.app/")
    .run_graphql(
        IntrospectionQuery::with_capabilities(
            SpecificationVersion::October2021.capabilities()
        )
    )
    .unwrap()
    .data
    .unwrap();

// And then convert it into a schema for easier use.
let schema = introspection_data.into_schema().unwrap();

assert_eq!(schema.query_type, "Query");

Detecting Capabilities

cynic-introspection also provides [CapabilitiesQuery], a query which can determine the capabilites of a remote GraphQL server. This can be paired with Introspection::with_capabilities:


use cynic::{QueryBuilder, http::ReqwestBlockingExt};
use cynic_introspection::{CapabilitiesQuery, IntrospectionQuery};

// First we run a capabilites query to check what the server supports
let capabilities = reqwest::blocking::Client::new()
    .post("https://swapi-graphql.netlify.app/.netlify/functions/index")
    .run_graphql(CapabilitiesQuery::build(()))
    .unwrap()
    .data
    .unwrap()
    .capabilities();

// Now we can safely run introspection, only querying for what the server supports.
let introspection_data = reqwest::blocking::Client::new()
    .post("https://swapi-graphql.netlify.app/.netlify/functions/index")
    .run_graphql(IntrospectionQuery::with_capabilities(capabilities))
    .unwrap()
    .data
    .unwrap();

// And then convert it into a schema for easier use.
let schema = introspection_data.into_schema().unwrap();

assert_eq!(schema.query_type, "Root");

Dependencies

~5.5MB
~84K SLoC