Skip to content

Commit cb00b63

Browse files
authored
Move back to built in ID (#774)
1 parent 4c32eb8 commit cb00b63

18 files changed

+121
-216
lines changed

docs/configuration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ public class GraphQlControllerTests
485485
public async Task Single()
486486
{
487487
var query = @"
488-
query ($id: Id!)
488+
query ($id: ID!)
489489
{
490490
company(id:$id)
491491
{
@@ -506,7 +506,7 @@ query ($id: Id!)
506506
public async Task Single_not_found()
507507
{
508508
var query = @"
509-
query ($id: Id!)
509+
query ($id: ID!)
510510
{
511511
company(id:$id)
512512
{
@@ -527,7 +527,7 @@ query ($id: Id!)
527527
public async Task Variable()
528528
{
529529
var query = @"
530-
query ($id: Id!)
530+
query ($id: ID!)
531531
{
532532
companies(ids:[$id])
533533
{

docs/defining-graphs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class Query :
7474
}
7575
}
7676
```
77-
<sup><a href='/src/Snippets/RootQuery.cs#L5-L22' title='Snippet source file'>snippet source</a> | <a href='#snippet-rootquery' title='Start of snippet'>anchor</a></sup>
77+
<sup><a href='/src/Snippets/RootQuery.cs#L3-L20' title='Snippet source file'>snippet source</a> | <a href='#snippet-rootquery' title='Start of snippet'>anchor</a></sup>
7878
<!-- endSnippet -->
7979

8080
`AddQueryField` will result in all matching being found and returned.

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;NU5104;CS1573</NoWarn>
5-
<Version>20.2.1</Version>
5+
<Version>21.0.0</Version>
66
<AssemblyVersion>1.0.0</AssemblyVersion>
77
<PackageTags>EntityFrameworkCore, EntityFramework, GraphQL</PackageTags>
88
<ImplicitUsings>true</ImplicitUsings>

src/GraphQL.EntityFramework/EfGraphQLConventions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ static void RegisterScalarsAndArgs(IServiceCollection services)
8383
services.AddSingleton<WhereExpressionGraph>();
8484
services.AddSingleton<OrderByGraph>();
8585
services.AddSingleton<ComparisonGraph>();
86-
services.AddSingleton<IdGraph>();
8786
services.AddSingleton<ConnectorGraph>();
8887
}
8988

src/GraphQL.EntityFramework/GraphApi/EfInterfaceGraphType.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,4 @@ public TDbContext ResolveDbContext(IResolveFieldContext<TSource> context) =>
4747

4848
public TDbContext ResolveDbContext(IResolveFieldContext context) =>
4949
GraphQlService.ResolveDbContext(context);
50-
51-
public override FieldBuilder<TSource, TProperty> Field<TProperty>(
52-
string name,
53-
Expression<Func<TSource, TProperty>> expression,
54-
bool nullable = false,
55-
Type? type = null)
56-
{
57-
OverrideIdAttribute.Convert<TProperty>(ref type);
58-
59-
return base.Field(name, expression, nullable, type);
60-
}
6150
}

src/GraphQL.EntityFramework/GraphApi/EfObjectGraphType.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,4 @@ public FieldBuilder<TSource, TReturn> AddSingleField<TReturn>(
7171
bool nullable = false)
7272
where TReturn : class =>
7373
GraphQlService.AddSingleField(this, name, resolve, mutate, graphType, nullable);
74-
75-
public override FieldBuilder<TSource, TProperty> Field<TProperty>(
76-
string name,
77-
Expression<Func<TSource, TProperty>> expression,
78-
bool nullable = false,
79-
Type? type = null)
80-
{
81-
OverrideIdAttribute.Convert<TProperty>(ref type);
82-
83-
return base.Field(name, expression, nullable, type);
84-
}
8574
}

src/GraphQL.EntityFramework/Mapping/Mapper.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,6 @@ static Type GraphTypeFromType(string name, Type propertyType, bool isNullable)
219219
{
220220
try
221221
{
222-
if (OverrideIdAttribute.TryGetIdType(propertyType, out var graphType))
223-
{
224-
return graphType;
225-
}
226222
if (propertyType.TryGetCollectionType(out var collectionGenericType))
227223
{
228224
if (isNullable)

src/GraphQL.EntityFramework/OverrideIdAttribute.cs

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

src/GraphQL.EntityFramework/Where/ArgumentReader.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,39 @@ string ArgumentToExpression(object argument)
2323
};
2424
}
2525

26-
var idsArgument = context.GetArgument(typeof(object), "ids");
27-
var idArgument = context.GetArgument(typeof(object), "id");
28-
if (idsArgument is null && idArgument is null)
26+
if (context.Arguments == null)
27+
{
28+
result = null;
29+
return false;
30+
}
31+
32+
var containsIds = context.Arguments.TryGetValue("ids", out var ids);
33+
var containsId = context.Arguments.TryGetValue("id", out var id);
34+
35+
if (!containsIds && !containsId)
36+
{
37+
result = null;
38+
return false;
39+
}
40+
41+
if (ids.Source == ArgumentSource.FieldDefault && id.Source == ArgumentSource.FieldDefault)
2942
{
3043
result = null;
3144
return false;
3245
}
3346

3447
var expressions = new List<string>();
3548

36-
if (idArgument is not null)
49+
if (id.Source != ArgumentSource.FieldDefault)
3750
{
38-
expressions.Add( ArgumentToExpression(idArgument));
51+
expressions.Add(ArgumentToExpression(id.Value!));
3952
}
4053

41-
if (idsArgument is not null)
54+
if (ids.Source != ArgumentSource.FieldDefault)
4255
{
43-
if (idsArgument is not IEnumerable<object> objCollection)
56+
if (ids.Value is not IEnumerable<object> objCollection)
4457
{
45-
throw new($"TryReadIds got an 'ids' argument of type '{idsArgument.GetType().FullName}' which is not supported.");
58+
throw new($"TryReadIds got an 'ids' argument of type '{ids.Value!.GetType().FullName}' which is not supported.");
4659
}
4760

4861
expressions.AddRange(objCollection.Select(ArgumentToExpression));
@@ -62,6 +75,7 @@ public static bool TryReadSkip(IResolveFieldContext context, out int skip)
6275
throw new("Skip cannot be less than 0.");
6376
}
6477
}
78+
6579
return result;
6680
}
6781

@@ -75,6 +89,7 @@ public static bool TryReadTake(IResolveFieldContext context, out int take)
7589
throw new("Take cannot be less than 0.");
7690
}
7791
}
92+
7893
return result;
7994
}
8095

@@ -98,7 +113,7 @@ static bool TryReadInt(string name, IResolveFieldContext context, out int value)
98113
return false;
99114
}
100115

101-
value = (int)argument;
116+
value = (int) argument;
102117
return true;
103118
}
104119
}

src/GraphQL.EntityFramework/Where/ArgumentsAppender.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ static QueryArgument<ListGraphType<NonNullGraphType<OrderByGraph>>> OrderByArgum
1212
Name = "orderBy"
1313
};
1414

15-
static QueryArgument<ListGraphType<NonNullGraphType<IdGraph>>> IdsArgument() =>
15+
static QueryArgument<ListGraphType<NonNullGraphType<IdGraphType>>> IdsArgument() =>
1616
new()
1717
{
1818
Name = "ids"
1919
};
2020

21-
static QueryArgument<IdGraph> IdArgument() =>
21+
static QueryArgument<IdGraphType> IdArgument() =>
2222
new()
2323
{
2424
Name = "id"

0 commit comments

Comments
 (0)