DOCS: Docs for various new graphql features (#10186)

This commit is contained in:
Aaron Carlino 2021-12-23 13:51:23 +13:00 committed by GitHub
parent 16d6ca5f4e
commit a7b8c9f038
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 0 deletions

View File

@ -41,6 +41,13 @@ Keep in mind that many of your changes will be in YAML, which also requires a fl
If you do not provide a `schema` parameter, the task will build all schemas. If you do not provide a `schema` parameter, the task will build all schemas.
[/info] [/info]
#### Controlling verbosity
You can set the verbosity of the output by using `verbosity=<value>`.
Available values are the constants found in `SilverStripe\GraphQL\Schema\Logger`, e.g. `INFO`, `DEBUG`, `WARNING`.
By default, the verbosity is set to `INFO`.
### Building on dev/build ### Building on dev/build
By default, all schemas will be built as a side-effect of `dev/build`. To disable this, change By default, all schemas will be built as a side-effect of `dev/build`. To disable this, change

View File

@ -279,6 +279,25 @@ Given the brevity of these type names, it's not inconceivable that you could run
collisions, particularly if you use feature-based namespacing. Fortunately, there are collisions, particularly if you use feature-based namespacing. Fortunately, there are
hooks you have available to help influence the typename. hooks you have available to help influence the typename.
#### Explicit type mapping
You can explicitly provide type name for a given class using the `typeMapping` setting in your schema config.
**app/_graphql/config.yml**
```yaml
typeMapping:
MyProject\MyApp\Page: SpecialPage
```
It may be necessary to use `typeMapping` in projects that have a lot of similar class names in different namespaces, which will cause a collision
when the type name is derived from the class name. The most case for this
is the `Page` class, which is both at the root namespace and often in your
app namespace, e.g. `MyApp\Models\Page`.
#### The type formatter #### The type formatter
The `type_formatter` is a callable that can be set on the `DataObjectModel` config. It takes The `type_formatter` is a callable that can be set on the `DataObjectModel` config. It takes

View File

@ -13,6 +13,28 @@ Docs for the current stable version (3.x) can be found
[here](https://github.com/silverstripe/silverstripe-graphql/tree/3) [here](https://github.com/silverstripe/silverstripe-graphql/tree/3)
[/alert] [/alert]
## Debugging the generated code
By default, the generated PHP code is put into obfuscated classnames and filenames to prevent poisoning the search
tools within IDEs. Without this, you can search for something like "Page" in your IDE and get both a generated GraphQL type (probably not what you want) and a DataObject (more likely what you want) in the results and have no easy way of differentiating between the two.
When debugging, however, it's much easier if these classnames are human-readable. To turn on debug mode, add `DEBUG_SCHEMA=1` to your environment file and the classnames and filenames in the generated code directory will match their type names.
[warning]
Take care not to use `DEBUG_SCHEMA=1` as an inline environment variable to your build command, e.g. `DEBUG_SCHEMA=1 vendor/bin/sake dev/graphql/build` because any activity that happens at run time, e.g. querying the schema will fail, since the environment variable is no longer set.
[/warning]
In live mode, full obfuscation kicks in and the filenames become unreadable. You can only determine the type they map
to by looking at the generated classes and finding the `// @type:<typename>` inline comment, e.g. `// @type:Page`.
This obfuscation is handled by the `NameObfuscator` interface. See the `config.yml` file in the GraphQL module for
the various implementations, which include:
* `NaiveNameObfuscator`: Filename/Classname === Type name
* `HybridNameObfuscator`: Filename/Classname is a mix of the typename and a hash (default).
* `HashNameObfuscator`: Filename/Classname is a md5 hash of the type name (non-dev only).
## Getting the type name for a model class ## Getting the type name for a model class
Often times, you'll need to know the name of the type given a class name. There's a bit of context to this. Often times, you'll need to know the name of the type given a class name. There's a bit of context to this.