Skip to content

feat: add schema_paths for loading schema from local paths and installed packages AR-3#439

Open
Minister944 wants to merge 4 commits into
mainfrom
AR-3-local-schema-external-package-resolution
Open

feat: add schema_paths for loading schema from local paths and installed packages AR-3#439
Minister944 wants to merge 4 commits into
mainfrom
AR-3-local-schema-external-package-resolution

Conversation

@Minister944

@Minister944 Minister944 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Introduce a new schema_paths setting that builds the GraphQL schema from
multiple sources. Each entry is resolved either as a dotted Python attribute
path (e.g. pkg.SCHEMA_DIR or pkg.get_schema_files) - useful for pulling
type definitions from installed packages - or as a local file/directory path.

  • schema.py: add resolve_schema_paths and get_graphql_schema_from_paths
  • main.py: wire schema_paths into both client and graphqlschema strategies
  • settings.py: add the schema_paths field and make the three schema sources
    (schema_path, schema_paths, remote_schema_url) mutually exclusive -
    providing more than one now raises InvalidConfiguration; simplify
    using_remote_schema accordingly
  • docs/README: document schema_paths and the mutual-exclusivity rule

CI/CD does not pass. This is an unrelated error that is being fixed as part of AR-6

Acknowledgements

While working on this, we noticed #431 by @esfomeado, which also tackled
loading the schema from more than one source. After discussing it as a team,
we went with a different approach - a dedicated schema_paths setting that
additionally resolves dotted Python attribute paths from installed packages -
which we felt fit the project better. Thanks @esfomeado for raising the problem
and for your contribution! 🙏

Co-authored-by: esfomeado 1906254+esfomeado@users.noreply.github.com

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 15c15ddb-d8ac-4ca6-8ee9-d4b6599e2d15

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch AR-3-local-schema-external-package-resolution

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread ariadne_codegen/schema.py Outdated
Comment thread ariadne_codegen/settings.py Outdated
Comment thread docs/02-configuration.md Outdated
Comment thread ariadne_codegen/schema.py Outdated
Comment thread ariadne_codegen/schema.py Outdated
Comment thread ariadne_codegen/schema.py
Comment thread ariadne_codegen/schema.py
Comment thread ariadne_codegen/schema.py Outdated
…led packages

Introduce a new `schema_paths` setting that builds the GraphQL schema from
multiple sources. Each entry is resolved either as a dotted Python attribute
path (e.g. `pkg.SCHEMA_DIR` or `pkg.get_schema_files`) — useful for pulling
type definitions from installed packages — or as a local file/directory path.

- schema.py: add `resolve_schema_paths` and `get_graphql_schema_from_paths`
- main.py: wire `schema_paths` into both `client` and `graphqlschema` strategies
- settings.py: add the `schema_paths` field and make the three schema sources
  (`schema_path`, `schema_paths`, `remote_schema_url`) mutually exclusive —
  providing more than one now raises InvalidConfiguration; simplify
  `using_remote_schema` accordingly
- docs/README: document `schema_paths` and the mutual-exclusivity rule
@Minister944 Minister944 force-pushed the AR-3-local-schema-external-package-resolution branch from cee0b53 to 79de200 Compare July 1, 2026 17:11
Comment thread docs/02-configuration.md

### `schema_paths` entries

Each entry in `schema_paths` can be any of the following:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say it must, not "can".

Comment thread docs/02-configuration.md
- **a path to a directory** - all `.graphql`, `.graphqls` and `.gql` files from it are included, eg. `./schemas/`
- **a path to a specific file** to be used, eg. `./foo/bar.graphql`

An import path that cannot be resolved (missing package, or the attribute no longer exists) raises a configuration error rather than being silently skipped.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove it. You declared the lists of possible values, it's rather obvious it will raise an error. Moreover, we do not have similar mentions like "when providing remote_schema_url which is invalid URL, it will raise an error".

Comment thread tests/test_schema.py
Comment on lines +660 to +689
def test_resolve_schema_paths_with_single_file(tmp_path, schema_str):
schema_file = tmp_path / "schema.graphql"
schema_file.write_text(schema_str, encoding="utf-8")

result = resolve_schema_paths([schema_file.as_posix()])

assert result == [schema_file]


def test_resolve_schema_paths_with_directory(schemas_directory):
result = resolve_schema_paths([schemas_directory.as_posix()])

names = {p.name for p in result}
assert "schema.graphql" in names
assert "user.graphql" in names


def test_resolve_schema_paths_with_multiple_local_sources(
tmp_path, schema_str, extra_type_str
):
file1 = tmp_path / "schema.graphql"
file1.write_text(schema_str, encoding="utf-8")
file2 = tmp_path / "user.graphql"
file2.write_text(extra_type_str, encoding="utf-8")

result = resolve_schema_paths([file1.as_posix(), file2.as_posix()])

assert file1 in result
assert file2 in result
assert len(result) == 2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what's the point to have three separate test cases here. The first one checks the single file, the second - a single directory, the last one: two files.

WDYT to have just a single test case, which tests reading local files, and provide as an input a list: single file and single directory.

Comment thread tests/test_schema.py
resolve_schema_paths(["some_pkg.SCHEMA_FILE"])


def test_resolve_schema_paths_existing_file_skips_importlib(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you propose to have a test like this? What's the purpose?

Comment thread tests/test_schema.py
mock_import.assert_not_called()


def test_resolve_schema_paths_accepts_file_with_any_extension(tmp_path, schema_str):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why this test is needed?

Comment thread tests/test_schema.py
mock_import.assert_not_called()


def test_resolve_schema_paths_accepts_local_dir_with_dots_in_name(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand to show the code works for dots in filenames. But are you sure we absolutely need to have two different test cases for file and for directory?

Comment thread tests/test_schema.py
mock_import.assert_not_called()


def test_resolve_schema_paths_with_path_attribute_pointing_to_file(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test case just a "file" version of the "directory" test test_resolve_schema_paths_with_path_attribute_pointing_to_directory? If so, why it lives here in the file, not directly below the other similar tests?

Comment thread tests/test_schema.py
assert result == [schema_file]


def test_resolve_schema_paths_raises_invalid_configuration_for_source_without_dot(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to keep all the test cases "for this bad data, it raises InvalidConfiguration" in one place. We had some tests like this above, then other test cases, now we have again tests like this.

Comment thread ariadne_codegen/schema.py
return schema


def get_graphql_schema_from_path(schema_path: str) -> GraphQLSchema:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider just


def get_graphql_schema_from_path(schema_path: str) -> GraphQLSchema:
    return get_graphql_schema_from_paths([Path(schema_path)])

With the current solution, bot "from_path" and "from_paths" uses similar blocks, but call them independently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants