tooluniverse.graphql_tool module¶
- tooluniverse.graphql_tool.build_schema(source: str | Source, assume_valid: bool = False, assume_valid_sdl: bool = False, no_location: bool = False, allow_legacy_fragment_variables: bool = False) GraphQLSchema [source][source]¶
Build a GraphQLSchema directly from a source document.
- tooluniverse.graphql_tool.parse(source: Source | str, no_location: bool = False, max_tokens: int | None = None, allow_legacy_fragment_variables: bool = False) DocumentNode [source][source]¶
Given a GraphQL source, parse it into a Document.
Throws GraphQLError if a syntax error is encountered.
By default, the parser creates AST nodes that know the location in the source that they correspond to. Setting the
`no_location`
parameter to False disables that behavior for performance or testing.Parser CPU and memory usage is linear to the number of tokens in a document, however in extreme cases it becomes quadratic due to memory exhaustion. Parsing happens before validation, so even invalid queries can burn lots of CPU time and memory. To prevent this, you can set a maximum number of tokens allowed within a document using the
`max_tokens`
parameter.Legacy feature (will be removed in v3.3):
If
`allow_legacy_fragment_variables``
is set to``True`
, the parser will understand and parse variable definitions contained in a fragment definition. They’ll be represented in the :attr:~graphql.language.FragmentDefinitionNode.variable_definitions
field of the :class:~graphql.language.FragmentDefinitionNode
.The syntax is identical to normal, query-defined variables. For example:
fragment A($var: Boolean = false) on T { ... }
- tooluniverse.graphql_tool.validate(schema: GraphQLSchema, document_ast: DocumentNode, rules: Collection[Type[ASTValidationRule]] | None = None, max_errors: int | None = None, type_info: TypeInfo | None = None) List[GraphQLError] [source][source]¶
Implements the “Validation” section of the spec.
Validation runs synchronously, returning a list of encountered errors, or an empty list if no errors were encountered and the document is valid.
A list of specific validation rules may be provided. If not provided, the default list of rules defined by the GraphQL specification will be used.
Each validation rule is a ValidationRule object which is a visitor object that holds a ValidationContext (see the language/visitor API). Visitor methods are expected to return GraphQLErrors, or lists of GraphQLErrors when invalid.
Validate will stop validation after a
`max_errors`
limit has been reached. Attackers can send pathologically invalid queries to induce a DoS attack, so by default`max_errors`
set to 100 errors.Providing a custom TypeInfo instance is deprecated and will be removed in v3.3.
- class tooluniverse.graphql_tool.BaseTool(tool_config)[source][source]¶
Bases:
object
- classmethod get_default_config_file()[source][source]¶
Get the path to the default configuration file for this tool type.
This method uses a robust path resolution strategy that works across different installation scenarios:
Installed packages: Uses importlib.resources for proper package resource access
Development mode: Falls back to file-based path resolution
Legacy Python: Handles importlib.resources and importlib_resources
Override this method in subclasses to specify a custom defaults file.
- Returns:
Path or resource object pointing to the defaults file
- tooluniverse.graphql_tool.register_tool(tool_type_name=None, config=None)[source][source]¶
Decorator to automatically register tool classes and their configs.
- Usage:
@register_tool(‘CustomToolName’, config={…}) class MyTool:
pass
- tooluniverse.graphql_tool.remove_none_and_empty_values(json_obj)[source][source]¶
Remove all key-value pairs where the value is None or an empty list
- class tooluniverse.graphql_tool.GraphQLTool(tool_config, endpoint_url)[source][source]¶
Bases:
BaseTool
- class tooluniverse.graphql_tool.OpentargetTool(tool_config)[source][source]¶
Bases:
GraphQLTool
- class tooluniverse.graphql_tool.OpentargetToolDrugNameMatch(tool_config, drug_generic_tool=None)[source][source]¶
Bases:
GraphQLTool
- class tooluniverse.graphql_tool.OpentargetGeneticsTool(tool_config)[source][source]¶
Bases:
GraphQLTool
- class tooluniverse.graphql_tool.DiseaseTargetScoreTool(tool_config, datasource_id=None)[source][source]¶
Bases:
GraphQLTool
Tool to extract disease-target association scores from specific data sources