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

__init__(tool_config)[source][source]
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:

  1. Installed packages: Uses importlib.resources for proper package resource access

  2. Development mode: Falls back to file-based path resolution

  3. 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

classmethod load_defaults_from_file()[source][source]

Load defaults from the configuration file

run(arguments=None)[source][source]

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

check_function_call(function_call_json)[source][source]
get_required_parameters()[source][source]

Retrieve required parameters from the endpoint definition. Returns: list: List of required parameters for the given endpoint.

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.validate_query(query_str, schema_str)[source][source]
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

tooluniverse.graphql_tool.execute_query(endpoint_url, query, variables=None)[source][source]
class tooluniverse.graphql_tool.GraphQLTool(tool_config, endpoint_url)[source][source]

Bases: BaseTool

__init__(tool_config, endpoint_url)[source][source]
run(arguments)[source][source]

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

class tooluniverse.graphql_tool.OpentargetTool(tool_config)[source][source]

Bases: GraphQLTool

__init__(tool_config)[source][source]
run(arguments)[source][source]

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

class tooluniverse.graphql_tool.OpentargetToolDrugNameMatch(tool_config, drug_generic_tool=None)[source][source]

Bases: GraphQLTool

__init__(tool_config, drug_generic_tool=None)[source][source]
run(arguments)[source][source]

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

class tooluniverse.graphql_tool.OpentargetGeneticsTool(tool_config)[source][source]

Bases: GraphQLTool

__init__(tool_config)[source][source]
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

__init__(tool_config, datasource_id=None)[source][source]
run(arguments)[source][source]

Extract disease-target scores for a specific datasource Arguments should contain: efoId, datasourceId (optional), pageSize (optional)