Skip to content

Feature/region fixes #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
63773f3
package fixes
Jul 17, 2018
06bac2f
changed templates to generate auto properties
Jul 17, 2018
81682dc
documents now emit C# classes, properties are pascal cased and have j…
Jul 17, 2018
cd521a5
removed useless class helpers, input types are now classes, scalar ty…
Jul 17, 2018
c743320
added xmldoc style comment support
Jul 17, 2018
a03f8f6
Finished Query creation
Jul 18, 2018
bbf0311
added mutation class generation + removed unused types
Jul 19, 2018
25896ca
formatting + skipping stuff we won't need
Jul 20, 2018
2f83985
Merge pull request #1 from agoda-com/feature/output-tests
jenol Jul 20, 2018
175928c
added System, updating readme
Jul 20, 2018
550173e
Update README.md
jenol Jul 20, 2018
612ba90
Update README.md
jenol Jul 20, 2018
d29fc33
Update README.md
jenol Jul 20, 2018
0eaac18
Update README.md
jenol Jul 20, 2018
e8f266c
Merge pull request #2 from agoda-com/feature/scalar-types
jenol Jul 20, 2018
ba521fb
added ci config
Jul 20, 2018
317be12
removed test part for now
Jul 20, 2018
0c97cd0
Merge pull request #3 from agoda-com/feature/ci
jenol Jul 20, 2018
044cb07
readme changes
Jul 23, 2018
f3fab9b
ci changes
Jul 23, 2018
e5de5ea
ci run
Jul 23, 2018
07375da
run generator
Jul 23, 2018
36d5d47
Added C# project + build.ps1
Jul 23, 2018
ae35d0a
updated build
Jul 23, 2018
a5d5690
ci changes
Jul 23, 2018
b6201b5
ci changes
Jul 23, 2018
205115c
removed test project
Jul 23, 2018
6fd04ea
removed .net core project
Jul 23, 2018
f22624d
appveyor.yml fixes
Jul 23, 2018
94e82b4
fixing nuget restore issue
Jul 23, 2018
3ca67e5
nuget restore fix
Jul 23, 2018
6a39aa6
removed generated file
Jul 23, 2018
b67b167
appveyor.yml ps run fix
Jul 23, 2018
413add9
appveyor.yml fixes
Jul 23, 2018
e52b136
fixes in build.ps1 to download dependencies
Jul 23, 2018
2074963
ignore babel warnings for now
Jul 23, 2018
0047fc1
fixing babel
Jul 23, 2018
06045e7
run node 8
Jul 23, 2018
87e3f95
Merge pull request #4 from agoda-com/feature/tslint
jenol Jul 24, 2018
0dfb0b6
added publish step
Jul 24, 2018
919f9c4
npm changes
Jul 24, 2018
b9f06aa
trying to fix npm publish
Jul 24, 2018
ec1c779
removed pack
Jul 24, 2018
e97a96a
publish only from master
Jul 24, 2018
9b59589
publish on master activated
Jul 24, 2018
8b94339
Merge pull request #5 from agoda-com/feature/npm-publish
jenol Jul 24, 2018
23f7998
added .npmignore
Jul 25, 2018
451e5a6
made T covariant
Jul 31, 2018
cc6e415
updated badges
Jul 31, 2018
34779a4
added missing models + fixed generic escaping
Aug 14, 2018
e4c4c84
Update documents.handlebars
ratchapol-an Aug 16, 2018
6f17645
Update documents.handlebars
ratchapol-an Aug 16, 2018
5a45a56
Merge pull request #10 from agoda-com/feature/export-property
jenol Aug 16, 2018
c564203
fixed escaping issues
Aug 16, 2018
61cdd57
Merge branch 'master' into feature/mutation-arg-fix
Aug 16, 2018
a373bdd
property type fix
Aug 16, 2018
ba3b124
Merge pull request #9 from agoda-com/feature/mutation-arg-fix
jenol Aug 16, 2018
fb29dc1
found a way to add missing mutation arguments but the fields are missing
Aug 17, 2018
71a5422
moved using to the top
Aug 17, 2018
ec2b329
Merge pull request #12 from agoda-com/feature/fix-missing-arg-types
jenol Aug 17, 2018
d364208
fixed regions
Aug 17, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ node_modules
npm-debug.log
dist
temp
yarn-error.log
yarn-error.log
/samples/GitHub/output/OutTest/bin
/samples/GitHub/output/OutTest/obj
/samples/GitHub/output/.vs
/samples/GitHub/output/packages
/samples/GitHub/output/OutTest/GitHubSchema.cs
15 changes: 15 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node_modules
npm-debug.log
temp
yarn-error.log
/samples
/src
appveyor.yml
publish.ps1
build.ps1
yarn.lock
/dist/helpers
/dist/*.ts
/dist/*.map
tsconfig.json
*.tgz
72 changes: 67 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
---
[![Build status](https://ci.appveyor.com/api/projects/status/f61k8b4hcwv8gdy2?svg=true)](https://ci.appveyor.com/project/jenol/graphql-codegen-csharp)
[![Build status](https://ci.appveyor.com/api/projects/status/f61k8b4hcwv8gdy2/branch/master?svg=true)](https://ci.appveyor.com/project/jenol/graphql-codegen-csharp/branch/master)

---

# CSharp Generator for Queries

We forked @netspective 's (Thanks dude!) project and changed it so the templates emit only the query objects and models. In our case it is better to work off the queries than having a query builder.

# Goals

- [x] Generate C# Query classes for Queries and Mutations
- [x] Generate C# Models for Query return types
- [ ] Emit multiple files
- [ ] Full integration testing of the CSharp code against a dokerized GraphQL server
- [ ] Type converters for `LocalDate` and some excotic Scala scalar types we have

# CSharp template

Expand All @@ -16,8 +28,6 @@ For executing the template, install [**graphql-code-generator**](https://github.

Once we install graphql-code-generator, clone this project into your workspace.



After cloning the project, we can either install or build the template to function the graphql code generator.

Install the template using `npm install` command from the project folder path.
Expand All @@ -36,4 +46,56 @@ Other **Cli** Flag options are listed [here](https://github.com/dotansimha/graph

Once the C# code got generated, add the file into class library project in Visual Studio.

Build the project and check if any type errors are there.
Build the project and check if any type errors are there.

## CI

### AppVeyor

https://ci.appveyor.com/project/jenol/graphql-codegen-csharp

## Examples

### Queries

* `dummy.graphql` https://gist.github.com/jenol/a07b2fe602c8bb0c9b7aefe89f745eae.js
* `update.graphql` https://gist.github.com/jenol/d20df6609ae44e7fb64674f17a5622c1

### Output

* `Classes.cs` https://gist.github.com/jenol/6346f2b5a6d5397495aba7734c01e0ea

The Query objects can be called with a http client for example:

```
public class GraphqlClient
{
private const string _contentType = "application/json"; // "application/graphql";
private static readonly HttpClient _client = new HttpClient();

private readonly string _graphQlUrl;

public GraphqlClient(string graphQlUrl)
{
_graphQlUrl = graphQlUrl;
}

public async Task<T> ExecuteAsync<T>(IQuery<T> query)
{
var json = query.GetQueryText();

var response = await _client.PostAsync(_graphQlUrl, new StringContent(json, Encoding.UTF8, _contentType));

var responseString = await response.Content.ReadAsStringAsync();

return query.GetParsedObject(responseString);
}
}
```

```
var client = new GraphqlClient("http://bk-qaycsa-1001/v2/graphql");
var result = await client.ExecuteAsync(new Generated.MyQuery.Query(1));
```


25 changes: 25 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Test against the latest version of this Node.js version
environment:
nodejs_version: "8"

cache:
- packages -> **\packages.config # preserve "packages" directory in the root of build folder but will reset it if packages.config is modified
- node_modules # local npm modules
- '%APPDATA%\npm-cache'

# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
- ps: .\build.ps1

before_build:
- nuget restore samples\GitHub\output\OutTest.sln

test: off

build:
project: samples\GitHub\output\OutTest.sln

after_build:
- ps: .\publish.ps1
42 changes: 42 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#$ErrorActionPreference = "Stop"

$scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent

cd $scriptDir

$nodeVersion = node -v
$npmVersion = npm -v
$yarnVersion = yarn -v

Write-Output "-------------------------------------------"
Write-Output "Node: $nodeVersion, Npm: $npmVersion, Yarn: $yarnVersion"
Write-Output "-------------------------------------------"
Write-Output "Build project"
try{
$a = yarn install --non-interactive
}
catch{
}
yarn build
Write-Output "-------------------------------------------"
Write-Output "Running Generator"

$schemaPath = Join-Path $scriptDir "samples/GitHub/input/GitHubSchema.json"
$outPath = Join-Path $scriptDir "samples/GitHub/output/OutTest/GitHubSchema.cs"
$queryPath = Join-Path $scriptDir "samples/GitHub/input/*.graphql"
$templatePath = Join-Path $scriptDir "dist"

Write-Output "Schema Path: $schemaPath"
Write-Output "Output Path: $outPath"
Write-Output "Query Path: $queryPath"
Write-Output "Template Path: $templatePath"

try{
Write-Output "yarn gql-gen --schema $schemaPath --template $templatePath --out $outPath $queryPath --non-interactive"

$a = yarn gql-gen --schema $schemaPath --template $templatePath --out $outPath $queryPath --non-interactive
}
catch{
}

Write-Output "-------------------------------------------"
Loading