mirumee / ariadne-codegen

Generate fully typed Python client for any GraphQL API from schema, queries and mutations
BSD 3-Clause "New" or "Revised" License
268 stars 35 forks source link

graphqlschema option saves Python to .graphql files #271

Closed dhay closed 9 months ago

dhay commented 9 months ago

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 commented 9 months ago

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.