-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathFieldAwareGraphType.cs
More file actions
33 lines (30 loc) · 965 Bytes
/
FieldAwareGraphType.cs
File metadata and controls
33 lines (30 loc) · 965 Bytes
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
using System;
using System.Linq.Expressions;
using GraphQL;
using GraphQL.Builders;
using Graphql.Extensions.FieldEnums.Types.Extensions;
using GraphQL.Types;
namespace Graphql.Extensions.FieldEnums.Types
{
public class FieldAwareGraphType<TSourceType> : ObjectGraphType<TSourceType>
{
public override FieldBuilder<TSourceType, TProperty> Field<TProperty>
(
string name,
Expression<Func<TSourceType, TProperty>> expression,
bool nullable = false,
Type type = null
)
{
var result = base
.Field(name, expression, nullable, type)
.WithOriginalName(expression.NameOf())
.WithSourceType(typeof(TSourceType));
if (result.FieldType.Name.Contains("ID"))
{
result.FieldType.Name = result.FieldType.Name.Replace("ID", "Id");
}
return result;
}
}
}