Skip to content

Commit 027f29a

Browse files
committed
testing
1 parent c7f84a3 commit 027f29a

File tree

2 files changed

+71
-8
lines changed

2 files changed

+71
-8
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: test-released-version
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
version:
6+
description: 'the version to be tested'
7+
required: true
8+
9+
jobs:
10+
11+
test-non-windows-image:
12+
name: 'Build Non-Windows Image'
13+
strategy:
14+
matrix:
15+
os: [ 'ubuntu-latest', 'macos-latest' ]
16+
include:
17+
- os: 'ubuntu-latest'
18+
label: 'linux'
19+
- os: 'macos-latest'
20+
label: 'mac'
21+
runs-on: ${{matrix.os}}
22+
23+
24+
steps:
25+
- name: 'Setup Node'
26+
uses: actions/setup-node@2
27+
with:
28+
node-version: 12.x
29+
30+
- name: 'install'
31+
run: npm i -g graphql-anonymizer@${{github.event.inputs.version}}
32+
33+
- name: 'run'
34+
id: run-anonymizer
35+
run: "::set-output name=result::$(graphql-anonymizer <<< 'type Query{a:String}')"
36+
37+
- name: 'test'
38+
run: echo ${{steps.run-anonymizer.outputs.result}}
39+

src/main/java/Main.java

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,59 @@
1+
import graphql.Directives;
12
import graphql.schema.GraphQLSchema;
3+
import graphql.schema.idl.DirectiveInfo;
24
import graphql.schema.idl.SchemaGenerator;
35
import graphql.schema.idl.SchemaParser;
46
import graphql.schema.idl.SchemaPrinter;
57
import graphql.schema.idl.TypeDefinitionRegistry;
68
import graphql.util.Anonymizer;
79
import picocli.CommandLine;
810

11+
import java.io.BufferedReader;
912
import java.io.File;
13+
import java.io.InputStreamReader;
1014
import java.nio.file.Files;
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
import java.util.Scanner;
18+
import java.util.StringTokenizer;
1119
import java.util.concurrent.Callable;
1220

1321
import static picocli.CommandLine.*;
1422

1523
@Command(name = "graphql-anonymizer", mixinStandardHelpOptions = true, version = "graphql-anonymizer 1.0",
16-
description = "Aononymize GraphQL schemas and queries.")
24+
description = "Anonymize GraphQL schemas and queries")
1725
public class Main implements Callable<String> {
1826

1927

20-
@Parameters(index = "0", description = "The GraphQL schema file")
21-
private File file;
28+
@Option(names = {"-s", "--schema"}, description = "The GraphQL schema file", paramLabel = "schema-file")
29+
private File schemaFile;
2230

23-
// @Option(names = {"-a", "--algorithm"}, description = "MD5, SHA-1, SHA-256, ...")
24-
// private String algorithm = "MD5";
31+
@Option(names = {"-v", "--verbose"}, description = "print out more details", defaultValue = "false")
32+
private boolean verbose;
2533

2634
@Override
2735
public String call() throws Exception {
28-
String schema = Files.readString(file.toPath());
29-
TypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(schema);
36+
String sdl;
37+
if (schemaFile != null) {
38+
sdl = Files.readString(schemaFile.toPath());
39+
} else {
40+
List<String> lines = new ArrayList<>();
41+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
42+
Scanner scanner = new Scanner(System.in);
43+
while (scanner.hasNext()) {
44+
lines.add(scanner.nextLine());
45+
}
46+
sdl = String.join("\n", lines);
47+
}
48+
if (verbose) {
49+
System.out.printf("Loaded schema: %s%n", sdl);
50+
}
51+
TypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(sdl);
3052
GraphQLSchema graphQLSchema = new SchemaGenerator().makeExecutableSchema(typeDefinitionRegistry, MockedWiring.MOCKED_WIRING);
3153
GraphQLSchema anonSchema = Anonymizer.anonymizeSchema(graphQLSchema);
32-
String printedSchema = new SchemaPrinter().print(anonSchema);
54+
SchemaPrinter.Options options = SchemaPrinter.Options.defaultOptions();
55+
options = options.includeDirectives(graphQLDirective -> !DirectiveInfo.isGraphqlSpecifiedDirective(graphQLDirective));
56+
String printedSchema = new SchemaPrinter(options).print(anonSchema);
3357
System.out.println(printedSchema);
3458
return printedSchema;
3559
}

0 commit comments

Comments
 (0)