Skip to content

Commit 88d47d1

Browse files
committed
graphql with 2 arguments
1 parent 8ff0e72 commit 88d47d1

6 files changed

Lines changed: 70 additions & 7 deletions

File tree

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ variables:
1010
solution: '**/*.sln'
1111
buildPlatform: 'Any CPU'
1212
buildConfiguration: 'Release'
13-
deployNuget: '0'
13+
deployNuget: '1'
1414

1515
steps:
1616
- task: NuGetToolInstaller@1

src/NetCore2Blockly/NetCore2Blockly/ExtensionMethods/ActionInfoExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public static string GenerateCommandName(this ActionInfo actionInfo)
6767
.Replace(@"\", "_")
6868
.Replace(@"?", "_")
6969
.Replace(@"=", "_")
70+
.Replace("\"", "_")
71+
.Replace(":", "_")
7072
;
7173
return $"{nameCommand}_{actionInfo.Verb}";
7274

src/NetCore2Blockly/NetCore2Blockly/GraphQL/GraphQLActionInfo.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,20 @@ internal void Init()
4848
Params.Add(arg.Name, (typeInGraph, BindingSourceDefinition.Query));
4949
}
5050
argsInQuery = string.Join(",",
51-
Params.Select(it=>it.Key +":{" +it.Key+"}")
51+
f.Args
52+
.Select(it=>new { it.Name, isString=(it.Type.Name == "String") })
53+
.Select(it=>it.Name +":"
54+
+ (it.isString ? "\"" : "")
55+
+ "{" +it.Name +"}"
56+
+ (it.isString ? "\"" : "")
57+
)
5258

5359
);
5460
argsInQuery = $"({argsInQuery})";
5561
}
5662

5763
RelativeRequestUrl = "/graphql?query={" + f.Name + argsInQuery+ "{"+ ret +"}}";
64+
this.
5865
Verb = "GET";
5966
ReturnType = BlocklyType.CreateValue(null);
6067

src/NetCore2Blockly/TestBlocklyHtml/GraphQL/DepartmentRepository.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System.Collections.Generic;
1+

2+
using Microsoft.EntityFrameworkCore;
3+
using System;
4+
using System.Collections.Generic;
25
using System.Linq;
36
using System.Threading.Tasks;
47
using TestBlocklyHtml.DB;
@@ -17,18 +20,32 @@ public DepartmentRepository(testsContext context)
1720
public async Task<IEnumerable<Department>> GetDepartment()
1821
{
1922

20-
var items= await _context.Department.ToArrayAsync();
23+
var items= await _context.Department.AsQueryable().ToArrayAsync();
2124
return items;
2225
}
2326

2427
public async Task<Department> GetOneDepartment(int id)
2528
{
26-
return await _context.Department.FirstOrDefaultAsync(dep => dep.Iddepartment == id);
29+
return await _context.Department.AsQueryable().FirstOrDefaultAsync(dep => dep.Iddepartment == id);
2730
}
2831

2932
public async Task<IEnumerable<Employee>> GetEmployees()
3033
{
31-
return await _context.Employee.ToListAsync();
34+
return await _context.Employee.AsQueryable().ToListAsync();
35+
}
36+
37+
internal Task<Employee[]> GetEmployeesAfterName(string empName, string depName)
38+
{
39+
var data = _context.Employee.AsQueryable();
40+
if(!string.IsNullOrWhiteSpace(empName))
41+
{
42+
data = data.Where(it => it.Name.Contains(empName));
43+
}
44+
if (!string.IsNullOrWhiteSpace(depName))
45+
{
46+
data = data.Where(it => it.Name.Contains(depName));
47+
}
48+
return data.AsQueryable().ToArrayAsync();
3249
}
3350
}
3451
}

src/NetCore2Blockly/TestBlocklyHtml/GraphQL/GetAllQuery.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ public GetAllQuery(DepartmentRepository departmentRepository)
2727
return departmentRepository.GetOneDepartment(id);
2828
}
2929
);
30+
31+
FieldAsync< ListGraphType<EmployeeOGT>>(
32+
"getEmployeeAfterName",
33+
arguments: new QueryArguments(
34+
new QueryArgument<StringGraphType> { Name = "employeeName" },
35+
new QueryArgument<StringGraphType> { Name = "departmentName" }
36+
37+
),
38+
resolve:async context =>
39+
{
40+
var empName = context.GetArgument<string>("employeeName");
41+
var depName = context.GetArgument<string>("departmentName");
42+
return await departmentRepository.GetEmployeesAfterName(empName,depName);
43+
}
44+
);
45+
3046
}
3147
}
3248
}

src/NetCore2Blockly/TestBlocklyHtml/wwwroot/doNotCopy/testing.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,7 @@ var testBlocks = [
21712171
<next>
21722172
<block type="text_print">
21732173
<value name="TEXT">
2174-
<block type="_graphql_query__getOneDepartment_id:_id___iddepartment name___id_GET">
2174+
<block type="_graphql_query__getOneDepartment_id__id___iddepartment name___id_GET">
21752175
<value name="val_id">
21762176
<shadow type="math_number">
21772177
<field name="NUM">1</field>
@@ -2182,6 +2182,27 @@ var testBlocks = [
21822182
</block>
21832183
</next>
21842184
</block>
2185+
</xml>`
2186+
},
2187+
{
2188+
name: 'graphql 2 arg string',
2189+
data:`<xml xmlns="https://developers.google.com/blockly/xml">
2190+
<block type="text_print" x="95" y="213">
2191+
<value name="TEXT">
2192+
<block type="_graphql_query__getEmployeeAfterName_employeeName___employeeName__,departmentName___departmentName____idemployee name___employeeName_departmentName_GET">
2193+
<value name="val_employeeName">
2194+
<shadow type="text">
2195+
<field name="TEXT">erson</field>
2196+
</shadow>
2197+
</value>
2198+
<value name="val_departmentName">
2199+
<shadow type="text">
2200+
<field name="TEXT">IT</field>
2201+
</shadow>
2202+
</value>
2203+
</block>
2204+
</value>
2205+
</block>
21852206
</xml>`
21862207
}
21872208
]

0 commit comments

Comments
 (0)