MCPcopy Index your code
hub / github.com/davidpdrsn/juniper-from-schema

github.com/davidpdrsn/juniper-from-schema @juniper-from-schema-code-gen-v0.5.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release juniper-from-schema-code-gen-v0.5.2 ↗ · + Follow
442 symbols 699 edges 65 files 8 documented · 2%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

juniper-from-schema

Build crates.io Documentation

This library contains a procedural macro that reads a GraphQL schema file, and generates the corresponding Juniper macro calls. This means you can have a real schema file and be guaranteed that it matches your Rust implementation. It also removes most of the boilerplate involved in using Juniper.

Example

Imagine you have a GraphQL schema like this:

schema {
  query: Query
}

type Query {
  helloWorld(name: String!): String! @juniper(ownership: "owned")
}

That can be implemented like so:

use juniper_from_schema::graphql_schema_from_file;

// This is the important line
graphql_schema_from_file!("readme_schema.graphql");

pub struct Context;

impl juniper::Context for Context {}

pub struct Query;

// This trait is generated by `graphql_schema_from_file!` based on the schema
impl QueryFields for Query {
    fn field_hello_world(
        &self,
        executor: &juniper::Executor<'_, Context>,
        name: String,
    ) -> juniper::FieldResult<String> {
        Ok(format!("Hello, {}!", name))
    }
}

pub struct Mutation;

// This trait is generated by `graphql_schema_from_file!` based on the schema
impl MutationFields for Mutation {
    fn field_noop(
      &self,
      executor: &juniper::Executor<'_, Context>,
    ) -> juniper::FieldResult<&bool> {
        Ok(&true)
    }
}

fn main() {
    let ctx = Context;

    let query = "query { helloWorld(name: \"Ferris\") }";

    let (result, errors) = juniper::execute(
        query,
        None,
        &Schema::new(Query, Mutation),
        &juniper::Variables::new(),
        &ctx,
    )
    .unwrap();

    assert_eq!(errors.len(), 0);
    assert_eq!(
        result
            .as_object_value()
            .unwrap()
            .get_field_value("helloWorld")
            .unwrap()
            .as_scalar_value::<String>()
            .unwrap(),
        "Hello, Ferris!",
    );
}

See the crate documentation for a usage examples and more info.

N+1s

If you're having issues with N+1 query bugs consider using juniper-eager-loading. It was built to integrate seamlessly with juniper-from-schema.

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Method 230
Class 118
Function 74
Enum 14
Interface 6

Languages

Rust100%

Modules by API surface

juniper-from-schema-code-gen/src/ast_pass/code_gen_pass.rs51 symbols
juniper-from-schema/tests/default_argument_values_test.rs27 symbols
juniper-from-schema-code-gen/src/ast_pass/code_gen_pass/gen_query_trails.rs24 symbols
juniper-from-schema-code-gen/src/ast_pass/ast_data_pass.rs20 symbols
juniper-from-schema/tests/end_to_end_test.rs19 symbols
juniper-from-schema-code-gen/src/ast_pass/schema_visitor.rs18 symbols
juniper-from-schema-code-gen/src/ast_pass/directive_parsing.rs16 symbols
juniper-from-schema/tests/converting_query_trails_test.rs15 symbols
juniper-from-schema-code-gen/src/ast_pass/error.rs15 symbols
juniper-from-schema/tests/query_trail_arguments.rs13 symbols
juniper-from-schema/tests/compile_pass/query_trail_methods_for_union_types.rs13 symbols
juniper-from-schema/tests/doc_test.rs12 symbols

For agents

$ claude mcp add juniper-from-schema \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page