Skip to content

Commit 32fed94

Browse files
authored
Fixed: byte[] cannot be defined as a custom scalar. (#345)
1 parent 0a232c3 commit 32fed94

File tree

112 files changed

+1573
-701
lines changed

Some content is hidden

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

112 files changed

+1573
-701
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ We are currently working on the following features that are proposed for the nex
302302
- [x] WebSockets
303303
- [ ] Schema Builder (in development - 0.11.0)
304304

305+
## GraphQL Compatibility Acceptance Tests
306+
307+
We are now investing to implement the GraphQL Compatibility Acceptance Tests for Hot Chocolate. We should have the first test running with Version 0.8.0 and should have this finished until Version 0.11.0.
308+
309+
More about GraphQL compatibility acceptance tests can be read [here](https://github.com/graphql-cats/graphql-cats).
310+
305311
## Documentation
306312

307313
For more examples and detailed documentation, click [here](http://hotchocolate.io).

src/Core.Tests/Execution/Utilities/VariableValueBuilderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public void CreateValues_IntValue_Int(int value)
236236
"query test($test: Int) { a }");
237237

238238
var variableValues = new Dictionary<string, object>();
239-
variableValues.Add("test", 1);
239+
variableValues.Add("test", value);
240240

241241
var resolver = new VariableValueBuilder(schema, operation);
242242

@@ -246,7 +246,7 @@ public void CreateValues_IntValue_Int(int value)
246246

247247
// assert
248248
int result = coercedVariableValues.GetVariable<int>("test");
249-
Assert.Equal(1, result);
249+
Assert.Equal(value, result);
250250
}
251251

252252
[Fact]

src/Core/Execution/DirectiveContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public object Result
6767
public CancellationToken RequestAborted =>
6868
_resolverContext.RequestAborted;
6969

70-
public T Argument<T>(string name) =>
70+
public T Argument<T>(NameString name) =>
7171
_resolverContext.Argument<T>(name);
7272

7373
public T CustomContext<T>() =>

src/Core/Execution/ResolverContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public ResolverContext(
7373

7474
public CancellationToken RequestAborted { get; }
7575

76-
public T Argument<T>(string name)
76+
public T Argument<T>(NameString name)
7777
{
7878
if (string.IsNullOrEmpty(name))
7979
{

src/Core/Execution/Utilities/FieldCollector.cs

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,37 +70,69 @@ private void ResolveFields(
7070
{
7171
if (selection is FieldNode fs)
7272
{
73-
string fieldName = fs.Name.Value;
74-
if (type.Fields.TryGetField(fieldName, out ObjectField field))
75-
{
76-
string name = fs.Alias == null ? fs.Name.Value : fs.Alias.Value;
77-
fields[name] = new FieldSelection(fs, field, name);
78-
}
79-
else
80-
{
81-
reportError(new QueryError(
82-
"Could not resolve the specified field."));
83-
}
73+
ResolveFieldSelection(type, fs, reportError, fields);
8474
}
85-
else if (selection is FragmentSpreadNode fragmentSpread)
75+
else if (selection is FragmentSpreadNode fragSpread)
8676
{
87-
Fragment fragment = _fragments.GetFragments(fragmentSpread.Name.Value)
88-
.FirstOrDefault(t => DoesFragmentTypeApply(type, t.TypeCondition));
89-
if (fragment != null)
90-
{
91-
CollectFields(type, fragment.SelectionSet, reportError, fields);
92-
}
77+
ResolveFragmentSpread(type, fragSpread, reportError, fields);
9378
}
94-
else if (selection is InlineFragmentNode inlineFragment)
79+
else if (selection is InlineFragmentNode inlineFrag)
9580
{
96-
Fragment fragment = _fragments.GetFragment(type, inlineFragment);
97-
if (DoesFragmentTypeApply(type, fragment.TypeCondition))
98-
{
99-
CollectFields(type, fragment.SelectionSet, reportError, fields);
100-
}
81+
ResolveInlineFragment(type, inlineFrag, reportError, fields);
10182
}
10283
}
10384

85+
private void ResolveFieldSelection(
86+
ObjectType type,
87+
FieldNode fieldSelection,
88+
Action<QueryError> reportError,
89+
Dictionary<string, FieldSelection> fields)
90+
{
91+
NameString fieldName = fieldSelection.Name.Value;
92+
if (type.Fields.TryGetField(fieldName, out ObjectField field))
93+
{
94+
string name = fieldSelection.Alias == null
95+
? fieldSelection.Name.Value
96+
: fieldSelection.Alias.Value;
97+
fields[name] = new FieldSelection(fieldSelection, field, name);
98+
}
99+
else
100+
{
101+
reportError(QueryError.CreateFieldError(
102+
"Could not resolve the specified field.",
103+
fieldSelection));
104+
}
105+
}
106+
107+
private void ResolveFragmentSpread(
108+
ObjectType type,
109+
FragmentSpreadNode fragmentSpread,
110+
Action<QueryError> reportError,
111+
Dictionary<string, FieldSelection> fields)
112+
{
113+
Fragment fragment = _fragments.GetFragment(
114+
fragmentSpread.Name.Value);
115+
116+
if (fragment != null && DoesTypeApply(fragment.TypeCondition, type))
117+
{
118+
CollectFields(type, fragment.SelectionSet, reportError, fields);
119+
}
120+
}
121+
122+
private void ResolveInlineFragment(
123+
ObjectType type,
124+
InlineFragmentNode inlineFragment,
125+
Action<QueryError> reportError,
126+
Dictionary<string, FieldSelection> fields)
127+
{
128+
Fragment fragment = _fragments.GetFragment(type, inlineFragment);
129+
if (DoesTypeApply(fragment.TypeCondition, type))
130+
{
131+
CollectFields(type, fragment.SelectionSet, reportError, fields);
132+
}
133+
}
134+
135+
104136
private bool ShouldBeIncluded(ISelectionNode selection)
105137
{
106138
if (selection.Directives.Skip(_variables))
@@ -110,20 +142,21 @@ private bool ShouldBeIncluded(ISelectionNode selection)
110142
return selection.Directives.Include(_variables);
111143
}
112144

113-
private bool DoesFragmentTypeApply(ObjectType objectType, IType type)
145+
private bool DoesTypeApply(IType typeCondition, ObjectType current)
114146
{
115-
if (type is ObjectType ot)
147+
if (typeCondition is ObjectType ot)
116148
{
117-
return ot == objectType;
149+
return ot == current;
118150
}
119-
else if (type is InterfaceType it)
151+
else if (typeCondition is InterfaceType it)
120152
{
121-
return objectType.Interfaces.ContainsKey(it.Name);
153+
return current.Interfaces.ContainsKey(it.Name);
122154
}
123-
else if (type is UnionType ut)
155+
else if (typeCondition is UnionType ut)
124156
{
125-
return ut.Types.ContainsKey(objectType.Name);
157+
return ut.Types.ContainsKey(current.Name);
126158
}
159+
127160
return false;
128161
}
129162
}

src/Core/Execution/Utilities/FragmentCollection.cs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace HotChocolate.Execution
88
{
99
internal sealed class FragmentCollection
1010
{
11-
private readonly Dictionary<string, List<Fragment>> _fragments =
12-
new Dictionary<string, List<Fragment>>();
11+
private readonly Dictionary<string, Fragment> _fragments =
12+
new Dictionary<string, Fragment>();
1313
private readonly ISchema _schema;
1414
private readonly DocumentNode _queryDocument;
1515

@@ -29,37 +29,41 @@ public FragmentCollection(ISchema schema, DocumentNode queryDocument)
2929
_queryDocument = queryDocument;
3030
}
3131

32-
public IReadOnlyCollection<Fragment> GetFragments(string fragmentName)
32+
public Fragment GetFragment(string fragmentName)
3333
{
3434
if (fragmentName == null)
3535
{
3636
throw new ArgumentNullException(nameof(fragmentName));
3737
}
3838

3939
if (!_fragments.TryGetValue(fragmentName,
40-
out List<Fragment> fragments))
40+
out Fragment fragment))
4141
{
42-
fragments = new List<Fragment>();
43-
fragments.AddRange(CreateFragments(fragmentName));
44-
_fragments[fragmentName] = fragments;
42+
fragment = CreateFragment(fragmentName);
43+
_fragments[fragmentName] = fragment;
4544
}
4645

47-
return fragments;
46+
return fragment;
4847
}
4948

50-
private IEnumerable<Fragment> CreateFragments(string fragmentName)
49+
private Fragment CreateFragment(string fragmentName)
5150
{
52-
foreach (FragmentDefinitionNode fragmentDefinition in
53-
_queryDocument.Definitions
54-
.OfType<FragmentDefinitionNode>()
55-
.Where(t => t.Name.Value == fragmentName))
51+
var fragmentDefinition = _queryDocument.Definitions
52+
.OfType<FragmentDefinitionNode>()
53+
.FirstOrDefault(t => string.Equals(
54+
t.Name.Value, fragmentName,
55+
StringComparison.Ordinal));
56+
57+
if (fragmentDefinition != null)
5658
{
5759
string typeName = fragmentDefinition.TypeCondition.Name.Value;
5860
if (_schema.TryGetType(typeName, out INamedType type))
5961
{
60-
yield return new Fragment(type, fragmentDefinition.SelectionSet);
62+
return new Fragment(type, fragmentDefinition.SelectionSet);
6163
}
6264
}
65+
66+
return null;
6367
}
6468

6569
public Fragment GetFragment(
@@ -78,15 +82,14 @@ public Fragment GetFragment(
7882

7983
string fragmentName = CreateInlineFragmentName(inlineFragment);
8084

81-
if (!_fragments.TryGetValue(fragmentName,
82-
out List<Fragment> fragments))
85+
if (!_fragments.TryGetValue(fragmentName, out Fragment fragment))
8386
{
84-
fragments = new List<Fragment>();
85-
fragments.Add(CreateFragment(parentType, inlineFragment));
86-
_fragments[fragmentName] = fragments;
87+
fragment = CreateFragment(parentType, inlineFragment);
88+
_fragments[fragmentName] = fragment;
89+
8790
}
8891

89-
return fragments.First();
92+
return fragment;
9093
}
9194

9295
private Fragment CreateFragment(
@@ -111,7 +114,8 @@ private Fragment CreateFragment(
111114
private string CreateInlineFragmentName(
112115
InlineFragmentNode inlineFragment)
113116
{
114-
return $"^__{inlineFragment.Location.Start}_{inlineFragment.Location.End}";
117+
return $"^__{inlineFragment.Location.Start}_" +
118+
inlineFragment.Location.End;
115119
}
116120
}
117121
}

src/Core/Validation/FieldMustBeDefinedVisitor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private bool HasOnylTypeNameField(SelectionSetNode selectionSet)
5959
.All(t => IsTypeNameField(t.Name.Value));
6060
}
6161

62-
private bool FieldExists(IComplexOutputType type, string fieldName)
62+
private bool FieldExists(IComplexOutputType type, NameString fieldName)
6363
{
6464
if (IsTypeNameField(fieldName))
6565
{
@@ -68,9 +68,9 @@ private bool FieldExists(IComplexOutputType type, string fieldName)
6868
return type.Fields.ContainsField(fieldName);
6969
}
7070

71-
private static bool IsTypeNameField(string fieldName)
71+
private static bool IsTypeNameField(NameString fieldName)
7272
{
73-
return fieldName.EqualsOrdinal(IntrospectionFields.TypeName);
73+
return fieldName.Equals(IntrospectionFields.TypeName);
7474
}
7575
}
7676
}

src/Core/Validation/FieldSelectionMergingVisitor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected override void VisitField(
5050
IType type,
5151
ImmutableStack<ISyntaxNode> path)
5252
{
53-
if (!field.Name.Value.EqualsOrdinal(IntrospectionFields.TypeName))
53+
if (!IntrospectionFields.TypeName.Equals(field.Name.Value))
5454
{
5555
if (TryGetSelectionSet(path, out SelectionSetNode selectionSet)
5656
&& _fieldSelectionSets.TryGetValue(selectionSet,
@@ -151,7 +151,8 @@ private bool CanFieldsInSetMerge(
151151
if (fieldA.DeclaringType == fieldB.DeclaringType)
152152
{
153153
if (fieldA.Field.Name.Value
154-
.EqualsOrdinal(fieldB.Field.Name.Value)
154+
.Equals(fieldB.Field.Name.Value,
155+
StringComparison.Ordinal)
155156
&& AreFieldArgumentsEqual(fieldA, fieldB))
156157
{
157158
return true;

src/Core/Validation/SubscriptionSingleRootFieldVisitor.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using HotChocolate.Utilities;
44
using HotChocolate.Language;
55
using HotChocolate.Types;
6+
using System;
67

78
namespace HotChocolate.Validation
89
{
@@ -55,8 +56,9 @@ protected override void VisitFragmentSpread(
5556
{
5657
FragmentDefinitionNode fragment = d.Definitions
5758
.OfType<FragmentDefinitionNode>()
58-
.FirstOrDefault(t =>
59-
t.Name.Value.EqualsOrdinal(fragmentSpread.Name.Value));
59+
.FirstOrDefault(t => t.Name.Value
60+
.Equals(fragmentSpread.Name.Value,
61+
StringComparison.Ordinal));
6062

6163
if (fragment != null)
6264
{

src/Language/ValidationUtils.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System;
2+
using System.Text;
23

34
namespace HotChocolate.Language
45
{
5-
public static class ValidationUtils
6+
public static class NameUtils
67
{
78
public static bool IsValidName(string name)
89
{
@@ -30,5 +31,32 @@ public static bool IsValidName(string name)
3031
return false;
3132
}
3233

34+
public static string RemoveInvalidCharacters(string name)
35+
{
36+
if (name == null || name.Length == 0)
37+
{
38+
return name;
39+
}
40+
41+
char[] namearray = name.ToCharArray();
42+
43+
if (!namearray[0].IsLetterOrUnderscore())
44+
{
45+
namearray[0] = '_';
46+
}
47+
48+
if (namearray.Length > 1)
49+
{
50+
for (int i = 1; i < namearray.Length; i++)
51+
{
52+
if (!namearray[i].IsLetterOrDigitOrUnderscore())
53+
{
54+
namearray[i] = '_';
55+
}
56+
}
57+
}
58+
59+
return new string(namearray);
60+
}
3361
}
3462
}

0 commit comments

Comments
 (0)