Skip to content

Commit c79e980

Browse files
Upgraded to Docusaurus v2 (#30)
1 parent 8f8740f commit c79e980

File tree

100 files changed

+30303
-11744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+30303
-11744
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
# Review gh actions docs if you want to further define triggers, paths, etc
8+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
9+
10+
jobs:
11+
deploy:
12+
name: Deploy to GitHub Pages
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-node@v3
17+
with:
18+
node-version: 18
19+
cache: yarn
20+
21+
- name: Install dependencies
22+
run: yarn install --frozen-lockfile
23+
- name: Build website
24+
run: yarn build
25+
26+
# Popular action to deploy to GitHub Pages:
27+
# Docs: https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus
28+
- name: Deploy to GitHub Pages
29+
uses: peaceiris/actions-gh-pages@v3
30+
with:
31+
github_token: ${{ secrets.GITHUB_TOKEN }}
32+
# Build output to publish to the `gh-pages` branch:
33+
publish_dir: ./build
34+
35+
publish_branch: master
36+
37+
# The following lines assign commit authorship to the official
38+
# GH-Actions bot for deploys to `gh-pages` branch:
39+
# https://github.com/actions/checkout/issues/13#issuecomment-724415212
40+
# The GH actions bot is used by default if you didn't specify the two fields.
41+
# You can swap them out with your own user credentials.
42+
# user_name: github-actions[bot]
43+
# user_email: 41898282+github-actions[bot]@users.noreply.github.com

.github/workflows/pr-build.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: PR Build
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
# Review gh actions docs if you want to further define triggers, paths, etc
8+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
9+
10+
jobs:
11+
test-deploy:
12+
name: Test deployment
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-node@v3
17+
with:
18+
node-version: 18
19+
cache: yarn
20+
21+
- name: Install dependencies
22+
run: yarn install --frozen-lockfile
23+
- name: Test build website
24+
run: yarn build

.gitignore

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
.DS_Store
1+
# Dependencies
2+
/node_modules
3+
4+
# Production
5+
/build
26

3-
node_modules
7+
# Generated files
8+
.docusaurus
9+
.cache-loader
410

5-
lib/core/metadata.js
6-
lib/core/MetadataBlog.js
11+
# Misc
12+
.DS_Store
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
717

8-
website/translated_docs
9-
website/build/
10-
website/yarn.lock
11-
website/node_modules
12-
website/i18n/*
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*

.prettierrc

Lines changed: 0 additions & 6 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
This repository contains the source code for the GraphQL ASP.NET documentation website. Clone the `develop` branch to view the code and update the documentation. The `master` branch contains the compiled static site served by github pages.
88

99

10-
_Documentation created using [Docusaurus v1.14.0](https://docusaurus.io)_
10+
_Documentation created using [Docusaurus v2](https://docusaurus.io)_

babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3+
};

build/publish-website.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.

docs/advanced/_category_.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"label": "Advanced",
3+
"position": 4,
4+
"collapsed": false
5+
}

docs/advanced/custom-scalars.md

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
id: custom-scalars
33
title: Custom Scalars
44
sidebar_label: Custom Scalars
5+
sidebar_position: 3
56
---
67

78
Scalars are the most basic, fundamental unit of content in GraphQL. It is one of two leaf types (the other being [ENUMS](../types/enums)). When a query is resolved the returned data will be a set of nested key/value pairs where every key is a string and every value is either another set of key/value pairs, an enum or a scalar.
@@ -12,11 +13,7 @@ This can be done for any value that can be represented as a simple set of charac
1213

1314
Lets say we wanted to build a scalar called `Money` that can handle both an amount and currency symbol. We might accept it in a query like this:
1415

15-
<div class="sideBySideCode hljs">
16-
<div>
17-
1816
```csharp
19-
// C# Controller
2017
public class InventoryController : GraphController
2118
{
2219
[QueryRoot("search")]
@@ -42,10 +39,7 @@ public class Money
4239
}
4340
```
4441

45-
</div>
46-
<div>
47-
48-
```javascript
42+
```graphql title="Using the Money Scalar"
4943
query {
5044
search(minPrice: "$18.45"){
5145
id
@@ -54,44 +48,38 @@ query {
5448
}
5549
```
5650

57-
</div>
58-
</div>
59-
<br/>
6051

6152
The query supplies the data as a quoted string, `"$18.45"`, but our action method receives a `Money` object. Internally, GraphQL senses that the value should be `Money` from the schema definition and invokes the correct resolver to parse the value and generate the .NET object that can be passed to our action method.
6253

6354
## Implement IScalarGraphType
6455

6556
To create a scalar graph type we need to implement `IScalarGraphType` and register it with GraphQL. The methods and properties of `IScalarGraphType` are as follows:
6657

67-
```csharp
68-
namespace GraphQL.AspNet.Interfaces.TypeSystem
58+
```csharp title="IScalarGraphType.cs"
59+
public interface IScalarGraphType
6960
{
70-
public interface IScalarGraphType
71-
{
72-
string Name { get; }
73-
string InternalName { get; }
74-
string Description { get; }
75-
TypeKind Kind { get; }
76-
bool Publish { get; }
77-
ScalarValueType ValueType { get; }
78-
Type ObjectType { get; }
79-
TypeCollection OtherKnownTypes { get; }
80-
ILeafValueResolver SourceResolver { get; }
81-
IScalarValueSerializer Serializer { get; }
82-
83-
bool ValidateObject(object item);
84-
}
61+
string Name { get; }
62+
string InternalName { get; }
63+
string Description { get; }
64+
TypeKind Kind { get; }
65+
bool Publish { get; }
66+
ScalarValueType ValueType { get; }
67+
Type ObjectType { get; }
68+
TypeCollection OtherKnownTypes { get; }
69+
ILeafValueResolver SourceResolver { get; }
70+
IScalarValueSerializer Serializer { get; }
71+
72+
bool ValidateObject(object item);
73+
}
8574

86-
public interface ILeafValueResolver
87-
{
88-
object Resolve(ReadOnlySpan<char> data);
89-
}
75+
public interface ILeafValueResolver
76+
{
77+
object Resolve(ReadOnlySpan<char> data);
78+
}
9079

91-
public interface IScalarValueSerializer
92-
{
93-
object Serialize(object item);
94-
}
80+
public interface IScalarValueSerializer
81+
{
82+
object Serialize(object item);
9583
}
9684
```
9785

@@ -148,7 +136,7 @@ If you throw `UnresolvedValueException` your error message will be delivered ver
148136
149137
Taking a look at the at the serializer for the `Guid` scalar type we can see that while internally the `System.Guid` struct represents the value we convert it to a string when serializing it. Most scalar implementations will serialize to a string.
150138

151-
```csharp
139+
```csharp title="GuidScalarSerializer.cs"
152140
public class GuidScalarSerializer : IScalarValueSerializer
153141
{
154142
public object Serialize(object item)
@@ -231,27 +219,25 @@ The completed Money custom scalar type
231219

232220
The last step in declaring a scalar is to register it with the runtime. Scalars are schema agnostic. They sit outside of any dependency injection context and must be registered directly with GraphQL.
233221

234-
```csharp
235-
// Startup.cs (other code)
236-
public void ConfigureServices(IServiceCollection services)
237-
{
238-
// register the scalar type to the global provider
239-
// BEFORE calling .AddGraphQL()
240-
GraphQLProviders.ScalarProvider.RegisterCustomScalar(typeof(MoneyScalarType));
222+
```csharp title="Register The Money Scalar "
223+
// register the scalar type to the global provider
224+
// BEFORE calling .AddGraphQL()
225+
GraphQLProviders.ScalarProvider.RegisterCustomScalar(typeof(MoneyScalarType));
241226

242-
services.AddGraphQL();
243-
}
227+
services.AddGraphQL();
244228
```
245229

230+
:::info
246231
Since our scalar is represented by a .NET class, if we don't pre-register it GraphQL will attempt to parse the `Money` class as an object graph type. Once registered as a scalar, any attempt to use `Money` as an object graph type will cause an exception.
232+
:::
247233

248234
## @specifiedBy Directive
249235

250236
GraphQL provides a special, built-in directive called `@specifiedBy` that allows you to supply a URL pointing to a the specification for your custom scalar. This url is used by various tools to additional data to your customers so they know how to interact with your scalar type. It is entirely optional.
251237

252238
The @specifiedBy directive can be applied to a scalar in all the same ways as other type system directives or by use of the special `[SpecifiedBy]` attribute.
253239

254-
```csharp
240+
```csharp title="Apply the @specifiedBy"
255241
// apply the directive to a single schema
256242
GraphQLProviders.ScalarProvider.RegisterCustomScalar(typeof(MoneyScalarType));
257243
services.AddGraphQL(o => {
@@ -275,7 +261,6 @@ public class MoneyScalarType : IScalarType
275261
{
276262
// ...
277263
}
278-
279264
```
280265

281266
## Tips When Developing a Scalar
@@ -297,8 +282,7 @@ Avoid the urge to start declaring a lot of custom scalars. In fact, chances are
297282
<div class="sideBySideCode hljs">
298283
<div>
299284

300-
```csharp
301-
// C# Controller
285+
```csharp title="Money as an Input Object Graph Type"
302286
public class InventoryController : GraphController
303287
{
304288
[QueryRoot("search")]
@@ -321,7 +305,7 @@ public class Money
321305
</div>
322306
<div>
323307

324-
```javascript
308+
```graphql title="Using the Money Input Object"
325309
query {
326310
search(minPrice: {
327311
symbol: "$"

0 commit comments

Comments
 (0)