Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphqlschema option saves Python to .graphql files #271

Closed
dhay opened this issue Jan 29, 2024 · 1 comment
Closed

graphqlschema option saves Python to .graphql files #271

dhay opened this issue Jan 29, 2024 · 1 comment

Comments

@dhay
Copy link

dhay commented Jan 29, 2024

I'm trying to use the graphqlschema command to save the GraphQL schema locally for use by the likes of IDEs, etc. However, when I invoke the command, I get a file named schema.graphql but the contents are Python code, not GraphQL syntax.

My pyproject.toml looks like this:

[tool.ariadne-codegen]
remote_schema_url = "https://api.mycompany.com/graphql"

# Env var has to be the entire value, not just the token
# https://github.com/mirumee/ariadne-codegen/issues/231
remote_schema_headers = {"Authorization" = "$GRAPH_INTROSPECTION_TOKEN"}

queries_path = "src/queries.graphql"
target_package_path = "src"
target_package_name = "graph_client"
target_file_path = "schema.graphql"
include_all_inputs = false
include_all_enums = false

and I'm invoking the tool like:

ariadne-codegen graphqlschema

I'm using ariadne-codegen 0.7.1

pip list | grep ariadne
ariadne                   0.21
ariadne-codegen           0.7.1

The first little bit of my schema.graphql that is generated looks like this:

from typing import List, cast

from graphql import (
    DirectiveLocation,
    GraphQLArgument,
    GraphQLBoolean,
    GraphQLDirective,
    GraphQLEnumType,
    GraphQLEnumValue,
    GraphQLField,
    GraphQLFloat,
    GraphQLID,
    GraphQLInputField,
    GraphQLInputObjectType,
    GraphQLInt,
    GraphQLInterfaceType,
    GraphQLList,
    GraphQLNonNull,
    GraphQLObjectType,
    GraphQLScalarType,
    GraphQLSchema,
    GraphQLString,
    GraphQLUnionType,
    Undefined,
)
from graphql.type.schema import TypeMap

type_map: TypeMap = {
    "MyType": GraphQLObjectType(
        name="MyType",
        description=None,
        interfaces=[],
        fields=lambda: {
            "start_time": GraphQLField(
                GraphQLNonNull(cast(GraphQLScalarType, type_map["DateTime"])),
                args={},
...
@rafalp rafalp closed this as completed Feb 2, 2024
@rafalp
Copy link
Contributor

rafalp commented Feb 2, 2024

Yes. This change was implemented but was not released yet, as per our changelog:

0.12.0 (UNRELEASED)
===================
...
- Added support to graphqlschema for saving schema as a GraphQL file.

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

No branches or pull requests

2 participants