mirumee / ariadne-website

The code that powers Ariadne website
https://ariadnegraphql.org
BSD 3-Clause "New" or "Revised" License
23 stars 37 forks source link

Fix typo #163

Closed pylipp closed 6 months ago

rafalp commented 6 months ago

Thank you for opening this PR but the api-reference.md document is generated from the docstrings embedded in Ariadne's codebase. Can you fix this typo there too?

pylipp commented 6 months ago

Sure, see https://github.com/mirumee/ariadne/pull/1140 :)

rafalp commented 6 months ago

Could you run the doc generator to verify that your changes are right for the current version?

pylipp commented 6 months ago

Sorry, I couldn't find any information on how to achieve this.

rafalp commented 6 months ago

Ah, sorry. You run python generate_reference.py in Ariadne repo's main directory. This will generate the docs directory with new files. Then copy-paste api-reference.md file to this PR to verify your typo is only change for master branch.

pylipp commented 6 months ago

This is the generated diff, there are more changes that happened on master unrelated to my PR...

diff --git a/docs/api-reference.md b/docs/api-reference.md
index b96d20c..dc0d6d6 100644
--- a/docs/api-reference.md
+++ b/docs/api-reference.md
@@ -55,7 +55,7 @@ Binds this `EnumType` instance to the instance of [GraphQL schema](https://graph
#### `bind_to_default_values`

```python
-def bind_to_default_values(self, schema: GraphQLSchema) -> None:
+def bind_to_default_values(self, _schema: GraphQLSchema) -> None:
   ...
```

@@ -66,6 +66,11 @@ lookup for default values defined in schema. Instead it simply pulls the
value from fields and arguments `default_value` attribute, which is
`None` by default.

+> **Deprecated:** Ariadne versions before 0.22 used
+`EnumType.bind_to_default_values` method to fix default enum values embedded
+in the [GraphQL schema](https://graphql-core-3.readthedocs.io/en/latest/modules/type.html#graphql.type.GraphQLSchema). Ariadne 0.22 release introduces universal
+`repair_schema_default_enum_values` utility in its place.
+

#### `validate_graphql_type`

@@ -185,7 +190,7 @@ Extension hook wrapping field's value resolution.
`**kwargs`: extra arguments from GraphQL to pass to resolver.

-# Example
+##### Example

`resolve` should handle both sync and async `next_`:

@@ -972,7 +977,7 @@ def set_alias(self, name: str, to: str) -> None:
   ...
```

-Set an alias resolver for the field name to given Python name.
+Set an alias resolver for the field name to given Python nme.

##### Required arguments
@@ -3249,48 +3254,46 @@ assert result == {
- - - - -

-## `resolve_to`
+## `repair_schema_default_enum_values`

```python
-def resolve_to(attr_name: str) -> Resolver:
+def repair_schema_default_enum_values(schema: GraphQLSchema) -> None:
   ...
```

-Create a resolver that resolves to given attribute or dict key.
-
-Returns a resolver function that can be used as resolver.
+Repairs Python values of default enums embedded in the [GraphQL schema](https://graphql-core-3.readthedocs.io/en/latest/modules/type.html#graphql.type.GraphQLSchema).

-Usually not used directly  but through higher level features like aliases
-or schema names conversion.
+Default enum values in the [GraphQL schemas](https://graphql-core-3.readthedocs.io/en/latest/modules/type.html#graphql.type.GraphQLSchema) are represented as strings with enum
+member names in Python. Assigning custom Python values to members of the
+`GraphQLEnumType` doesn't change those defaults.

-
-### Required arguments
-
-`attr_name`: a `str` with name of attribute or `dict` key to return from
-resolved object.
+This function walks the [GraphQL schema](https://graphql-core-3.readthedocs.io/en/latest/modules/type.html#graphql.type.GraphQLSchema), finds default enum values strings and,
+if this string is a valid GraphQL member name, swaps it out for a valid Python
+value.

- - - - -

-## `set_default_enum_values_on_schema`
+## `resolve_to`

```python
-def set_default_enum_values_on_schema(schema: GraphQLSchema) -> None:
+def resolve_to(attr_name: str) -> Resolver:
   ...
```

-Sets missing Python values for GraphQL enums in schema.
+Create a resolver that resolves to given attribute or dict key.

-Recursively scans [GraphQL schema](https://graphql-core-3.readthedocs.io/en/latest/modules/type.html#graphql.type.GraphQLSchema) for enums and their values. If `value`
-attribute is empty, its populated with with a string of its GraphQL name.
+Returns a resolver function that can be used as resolver.

-This string is then used to represent enum's value in Python instead of `None`.
+Usually not used directly  but through higher level features like aliases
+or schema names conversion.

-### Requires arguments
+### Required arguments

-`schema`: a [GraphQL schema](https://graphql-core-3.readthedocs.io/en/latest/modules/type.html#graphql.type.GraphQLSchema) to set enums default values in.
+`attr_name`: a `str` with name of attribute or `dict` key to return from
+resolved object.

- - - - -
@@ -3513,10 +3516,10 @@ schema = make_executable_schema(
- - - - -

-## `validate_schema_enum_values`
+## `validate_schema_default_enum_values`

```python
-def validate_schema_enum_values(schema: GraphQLSchema) -> None:
+def validate_schema_default_enum_values(schema: GraphQLSchema) -> None:
   ...
```

@@ -3572,4 +3575,30 @@ enum UserRole {
type User {
   id: ID!
}
+```
+
+
+### Example schema with invalid default input field argument
+
+This schema fails to validate because field `field` on input `ChildInput`
+specifies `INVALID` as default value and `INVALID` is not a member of
+the `Role` enum:
+
+```graphql
+type Query {
+    field(arg: Input = {field: {field: INVALID}}): String
+}
+
+input Input {
+    field: ChildInput
+}
+
+input ChildInput {
+    field: Role
+}
+
+enum Role {
+    USER
+    ADMIN
+}
```
\ No newline at end of file
rafalp commented 6 months ago

Looking at the diff, generated docs would revert back your typo fix:

+Set an alias resolver for the field name to given Python nme.
pylipp commented 6 months ago

My bad, when I run the generator from the correct branch, I can see that the change is not reverted.

rafalp commented 6 months ago

Thank you!