GraphQL Schema Modes & Context Injection¶
GraphQLBuilder compiles a GraphModel into an executable Strawberry GraphQL schema. You
can control how node types are mapped onto the GraphQL schema using SchemaMode, and override the active graph per
request using GraphQL execution context.
Schema Modes (SchemaMode)¶
1. Dynamic Mode (SchemaMode.DYNAMIC, Default)¶
In SchemaMode.DYNAMIC, GraphQLBuilder generates a dedicated GraphQL object type implementing GraphNode for each
registered node type in the graph (for example, ServiceNode, EndpointNode), along with pluralized root query fields
on Query (such as services, endpoints):
2. Static Mode (SchemaMode.STATIC)¶
In SchemaMode.STATIC, GraphQLBuilder uses a single GenericGraphNode type implementing GraphNode for all nodes
and exposes a fixed root Query interface (graph, nodes, edges, measure). This mode is useful when node types
are highly dynamic or when clients prefer a fixed GraphQL schema:
Dynamic Field Naming Strategies (DynamicFieldNaming)¶
When using SchemaMode.DYNAMIC, you can control how root query fields for dynamic node types are named using the dynamic_field_naming option on GraphQLBuilder:
DynamicFieldNaming.EXPLICIT(default): Preserves explicitsnake_casefield names (for example,git_commits,user_accounts). This guarantees full backward compatibility for existing client queries.DynamicFieldNaming.AUTO: Delegates field naming to Strawberry's configuration. By default (auto_camel_case=True), field names are automatically converted to standard GraphQLcamelCase(such asgitCommits,userAccounts).
Custom Strawberry Configuration¶
You can pass a custom strawberry.schema.config.StrawberryConfig to builder.build(config=...) or builder.schema(config=...) to customize casing, schema directives, or scalar mappings:
Context-Injected Graph Execution¶
By default, resolvers query the internal NetworkX graph built by GraphQLBuilder. You can also pass a custom nx.Graph
at execution time via context_value={'graph': custom_graph} without rebuilding the strawberry.Schema: