graphql-core icon indicating copy to clipboard operation
graphql-core copied to clipboard

`graphql.utilities.print_schema` module contents are hidden behind `utilities` package

Open tony opened this issue 2 years ago • 1 comments

Summary

graphql.utilities.__init__.py's export of print_schema function shadows the module of graphql.utilities.print_schema

https://github.com/graphql-python/graphql-core/blob/0c93b8452eed38d4f800c7e71cf6f3f3758cd1c6/src/graphql/utilities/init.py#L28-L31

So assume this:

from graphql.utilities import print_schema

Expected behavior

The module graphql.utilities.print_schema.

Results

As of v3.3.0a3

The function graphql.utilities.print_schema.print_schema() the function.

Discussion

https://github.com/graphql-python/graphql-core/blob/v3.3.0a3/src/graphql/utilities/print_schema.py#L32 does use a __ALL__, but its contents, which are typed, aren't exported.

Our use case

In earlier graphql-core versions, we would patch print_object - and during migration to graphql-core we found that wasn't available due to package structure.

tony avatar Oct 15 '23 19:10 tony

Sorry for the late answer. Is this still relevant?

The behavior is actually intended. You aren't supposed to import sub-modules - only the top-level modules are part of the API. This is also how it works in GraphQL.js. All the public functions in the sub-module are available from the top-level module. For instance, you can do from graphql.utilities import print_type. If you really want to get the sub-module to monkey-patch it (at your own risk), you can get it with inspect.get_module(print_schema).

Cito avatar Jan 25 '25 21:01 Cito