-
-
Notifications
You must be signed in to change notification settings - Fork 722
/
SchemaTests.cs
66 lines (56 loc) · 2.22 KB
/
SchemaTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.Threading.Tasks;
using CookieCrumble;
using HotChocolate.Execution;
using HotChocolate.Types;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
namespace HotChocolate.Caching.Tests;
public class SchemaTests
{
[Fact]
public async Task Allow_CacheControl_On_FieldDefinition()
{
var schema =
await new ServiceCollection()
.AddGraphQLServer()
.AddTypeExtension(typeof(Query))
.ConfigureSchema(
b => b.TryAddRootType(
() => new ObjectType(
d => d.Name(OperationTypeNames.Query)),
Language.OperationType.Query))
.AddCacheControl()
.BuildSchemaAsync();
schema.MatchInlineSnapshot(
"""
schema {
query: Query
}
type Book {
title: String! @cacheControl(maxAge: 5000)
description: String!
}
type Query {
book: Book! @cacheControl(maxAge: 0)
}
"The scope of a cache hint."
enum CacheControlScope {
"The value to cache is not tied to a single user."
PUBLIC
"The value to cache is specific to a single user."
PRIVATE
}
"The `@cacheControl` directive may be provided for individual fields or entire object, interface or union types to provide caching hints to the executor."
directive @cacheControl("The maximum amount of time this field's cached value is valid, in seconds." maxAge: Int "If `PRIVATE`, the field's value is specific to a single user. The default value is `PUBLIC`, which means the field's value is not tied to a single user." scope: CacheControlScope "If `true`, the field inherits the `maxAge` of its parent field." inheritMaxAge: Boolean) on OBJECT | FIELD_DEFINITION | INTERFACE | UNION
""");
}
[QueryType]
public static class Query
{
public static Book GetBook()
=> new Book("C# in depth.", "abc");
}
public record Book(
[property: CacheControl(5000)] string Title,
string Description);
}