Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit114ef93

Browse files
committed
GraphQL, shhhh....
1 parentcc2b193 commit114ef93

File tree

6 files changed

+297
-9
lines changed

6 files changed

+297
-9
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ _build/
77
_test.js
88
_test.d.ts
99
_test.re
10+
_test.graphql
1011
.merlin
1112
lib/retyped_node.js
1213
lib/bs

‎bindings/graphql.re‎

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
moduleInternal= {
2+
moduleKind= {
3+
typet=string;
4+
[@bs.module"graphql"] [@bs.scope"Kind"]externalname:t="NAME";
5+
[@bs.module"graphql"] [@bs.scope"Kind"]
6+
externaldocument:t="DOCUMENT";
7+
[@bs.module"graphql"] [@bs.scope"Kind"]
8+
externaloperationDefinition:t="OPERATION_DEFINITION";
9+
[@bs.module"graphql"] [@bs.scope"Kind"]
10+
externalvariableDefinition:t="VARIABLE_DEFINITION";
11+
[@bs.module"graphql"] [@bs.scope"Kind"]
12+
externalvariable:t="VARIABLE";
13+
[@bs.module"graphql"] [@bs.scope"Kind"]
14+
externalselectionSet:t="SELECTION_SET";
15+
[@bs.module"graphql"] [@bs.scope"Kind"]externalfield:t="FIELD";
16+
[@bs.module"graphql"] [@bs.scope"Kind"]
17+
externalargument:t="ARGUMENT";
18+
[@bs.module"graphql"] [@bs.scope"Kind"]
19+
externalfragmentSpread:t="FRAGMENT_SPREAD";
20+
[@bs.module"graphql"] [@bs.scope"Kind"]
21+
externalinlineFragment:t="INLINE_FRAGMENT";
22+
[@bs.module"graphql"] [@bs.scope"Kind"]
23+
externalfragmentDefinition:t="FRAGMENT_DEFINITION";
24+
[@bs.module"graphql"] [@bs.scope"Kind"]externalint:t="INT";
25+
[@bs.module"graphql"] [@bs.scope"Kind"]externalfloat:t="FLOAT";
26+
[@bs.module"graphql"] [@bs.scope"Kind"]externalstring:t="STRING";
27+
[@bs.module"graphql"] [@bs.scope"Kind"]externalboolean:t="BOOLEAN";
28+
[@bs.module"graphql"] [@bs.scope"Kind"]externalnull:t="NULL";
29+
[@bs.module"graphql"] [@bs.scope"Kind"]externalenum:t="ENUM";
30+
[@bs.module"graphql"] [@bs.scope"Kind"]externallist:t="LIST";
31+
[@bs.module"graphql"] [@bs.scope"Kind"]externalobject_:t="OBJECT";
32+
[@bs.module"graphql"] [@bs.scope"Kind"]
33+
externalobjectField:t="OBJECT_FIELD";
34+
[@bs.module"graphql"] [@bs.scope"Kind"]
35+
externaldirective:t="DIRECTIVE";
36+
[@bs.module"graphql"] [@bs.scope"Kind"]
37+
externalnamedType:t="NAMED_TYPE";
38+
[@bs.module"graphql"] [@bs.scope"Kind"]
39+
externallistType:t="LIST_TYPE";
40+
[@bs.module"graphql"] [@bs.scope"Kind"]
41+
externalnonNullType:t="NON_NULL_TYPE";
42+
[@bs.module"graphql"] [@bs.scope"Kind"]
43+
externalschemaDefinition:t="SCHEMA_DEFINITION";
44+
[@bs.module"graphql"] [@bs.scope"Kind"]
45+
externaloperationTypeDefinition:t="OPERATION_TYPE_DEFINITION";
46+
[@bs.module"graphql"] [@bs.scope"Kind"]
47+
externalscalarTypeDefinition:t="SCALAR_TYPE_DEFINITION";
48+
[@bs.module"graphql"] [@bs.scope"Kind"]
49+
externalobjectTypeDefinition:t="OBJECT_TYPE_DEFINITION";
50+
[@bs.module"graphql"] [@bs.scope"Kind"]
51+
externalfieldDefinition:t="FIELD_DEFINITION";
52+
[@bs.module"graphql"] [@bs.scope"Kind"]
53+
externalinputValueDefinition:t="INPUT_VALUE_DEFINITION";
54+
[@bs.module"graphql"] [@bs.scope"Kind"]
55+
externalinterfaceTypeDefinition:t="INTERFACE_TYPE_DEFINITION";
56+
[@bs.module"graphql"] [@bs.scope"Kind"]
57+
externalunionTypeDefinition:t="UNION_TYPE_DEFINITION";
58+
[@bs.module"graphql"] [@bs.scope"Kind"]
59+
externalenumTypeDefinition:t="ENUM_TYPE_DEFINITION";
60+
[@bs.module"graphql"] [@bs.scope"Kind"]
61+
externalenumValueDefinition:t="ENUM_VALUE_DEFINITION";
62+
[@bs.module"graphql"] [@bs.scope"Kind"]
63+
externalinputObjectTypeDefinition:t="INPUT_OBJECT_TYPE_DEFINITION";
64+
[@bs.module"graphql"] [@bs.scope"Kind"]
65+
externalscalarTypeExtension:t="SCALAR_TYPE_EXTENSION";
66+
[@bs.module"graphql"] [@bs.scope"Kind"]
67+
externalobjectTypeExtension:t="OBJECT_TYPE_EXTENSION";
68+
[@bs.module"graphql"] [@bs.scope"Kind"]
69+
externalinterfaceTypeExtension:t="INTERFACE_TYPE_EXTENSION";
70+
[@bs.module"graphql"] [@bs.scope"Kind"]
71+
externalunionTypeExtension:t="UNION_TYPE_EXTENSION";
72+
[@bs.module"graphql"] [@bs.scope"Kind"]
73+
externalenumTypeExtension:t="ENUM_TYPE_EXTENSION";
74+
[@bs.module"graphql"] [@bs.scope"Kind"]
75+
externalinputObjectTypeExtension:t="INPUT_OBJECT_TYPE_EXTENSION";
76+
[@bs.module"graphql"] [@bs.scope"Kind"]
77+
externaldirectiveDefinition:t="DIRECTIVE_DEFINITION";
78+
};
79+
typenode= {. "kind":Kind.t};
80+
moduleSource= {
81+
typet;
82+
[@bs.module"graphql"] [@bs.new]
83+
externalmake: (string,string) =>t="Source";
84+
};
85+
[@bs.module"graphql"]externalparse:Source.t =>node="";
86+
};
87+
88+
typesource= {
89+
body:string,
90+
name:string
91+
};
92+
93+
typeloc= {
94+
start:int,
95+
end_:int,
96+
source
97+
};
98+
99+
typedocument= {
100+
definitions:array(node),
101+
loc
102+
}
103+
andobjectTypeDefinition= {
104+
name:node,
105+
interfaces:array(node),
106+
directives:array(node),
107+
fields:array(node),
108+
loc
109+
}
110+
and fieldDefinition = {
111+
name: node,
112+
arguments: array(node),
113+
type_: node,
114+
directives: array(node),
115+
loc
116+
}
117+
and inputValueDefinition= {
118+
name: node,
119+
type_: node,
120+
defaultValue: option(node),
121+
directives: array(node),
122+
loc
123+
}
124+
and namedType= {
125+
name: node,
126+
loc
127+
}
128+
and nonNullType= {
129+
type_: node,
130+
loc
131+
}
132+
and name= {
133+
value: string,
134+
loc
135+
}
136+
and node=
137+
|Document(document)
138+
|ObjectTypeDefinition(objectTypeDefinition)
139+
|FieldDefinition(fieldDefinition)
140+
|InputValueDefinition(inputValueDefinition)
141+
|NamedType(namedType)
142+
|NonNullType(nonNullType)
143+
|Name(name)
144+
|Unknown(string);
145+
146+
moduleDecoder= {
147+
letsource= json=>
148+
Json.Decode.{
149+
body: json|> field("body", string),
150+
name: json|> field("name", string)
151+
};
152+
letloc= json=>
153+
Json.Decode.{
154+
start: json|> field("start", int),
155+
end_: json|> field("end", int),
156+
source: json|> field("source", source)
157+
};
158+
externalnodeToJson:Internal.node =>Js.Json.t="%identity";
159+
letrecdecoders=[
160+
(Internal.Kind.document, document),
161+
(Internal.Kind.objectTypeDefinition, objectTypeDefinition),
162+
(Internal.Kind.fieldDefinition, fieldDefinition),
163+
(Internal.Kind.inputValueDefinition, inputValueDefinition),
164+
(Internal.Kind.namedType, namedType),
165+
(Internal.Kind.nonNullType, nonNullType),
166+
(Internal.Kind.name, name)
167+
]
168+
andnode= json=> {
169+
letkind= json|>Json.Decode.field("kind",Json.Decode.string);
170+
letdecoder=
171+
try (List.assoc(kind, decoders)) {
172+
|_=> unknown
173+
};
174+
decoder(json);
175+
}
176+
anddocument= json=>
177+
Document(
178+
Json.Decode.{
179+
definitions: json|> field("definitions", array(node)),
180+
loc: json|> field("loc", loc)
181+
}
182+
)
183+
andobjectTypeDefinition= json=>
184+
ObjectTypeDefinition(
185+
Json.Decode.{
186+
name: json|> field("name", node),
187+
interfaces: json|> field("interfaces", array(node)),
188+
directives: json|> field("directives", array(node)),
189+
fields: json|> field("fields", array(node)),
190+
loc: json|> field("loc", loc)
191+
}
192+
)
193+
andfieldDefinition= json=>
194+
FieldDefinition(
195+
Json.Decode.{
196+
name: json|> field("name", node),
197+
arguments: json|> field("arguments", array(node)),
198+
type_: json|> field("type", node),
199+
directives: json|> field("directives", array(node)),
200+
loc: json|> field("loc", loc)
201+
}
202+
)
203+
andinputValueDefinition= json=>
204+
InputValueDefinition(
205+
Json.Decode.{
206+
name: json|> field("name", node),
207+
type_: json|> field("type", node),
208+
defaultValue: json|> optional(field("defaultValue", node)),
209+
directives: json|> field("directives", array(node)),
210+
loc: json|> field("loc", loc)
211+
}
212+
)
213+
andnamedType= json=>
214+
NamedType(
215+
Json.Decode.{
216+
name: json|> field("name", node),
217+
loc: json|> field("loc", loc)
218+
}
219+
)
220+
andnonNullType= json=>
221+
NonNullType(
222+
Json.Decode.{
223+
type_: json|> field("type", node),
224+
loc: json|> field("loc", loc)
225+
}
226+
)
227+
andname= json=>
228+
Name(
229+
Json.Decode.{
230+
value: json|> field("value", string),
231+
loc: json|> field("loc", loc)
232+
}
233+
)
234+
andunknown= json=> {
235+
letkind=Json.Decode.field("kind",Json.Decode.string, json);
236+
Unknown(kind);
237+
};
238+
letdecode= graphqlNode=> {
239+
letjson= nodeToJson(graphqlNode);
240+
node(json);
241+
};
242+
};
243+
244+
letparse= (fileName:string, source:string)=> {
245+
letsourceFile=Internal.Source.make(source, fileName);
246+
letparsedSource=Internal.parse(sourceFile);
247+
Decoder.decode(parsedSource);
248+
};

‎package.json‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
"type":"git",
1616
"url":"https://github.com/rrdelaney/ReasonablyTyped"
1717
},
18-
"keywords": ["Reason","OCaml","Bucklescript","Flow"],
18+
"keywords": [
19+
"Reason",
20+
"OCaml",
21+
"Bucklescript",
22+
"Flow"
23+
],
1924
"author":"Ryan Delaney <rrdelaney@outlook.com>",
2025
"license":"MIT",
2126
"bugs": {
@@ -26,6 +31,7 @@
2631
"@glennsl/bs-json":"^1.1.2",
2732
"babel-code-frame":"^6.26.0",
2833
"chalk":"^2.1.0",
34+
"graphql":"^0.13.2",
2935
"meow":"^3.7.0",
3036
"reason":"^3.0.0",
3137
"typescript":"^2.7.2"
@@ -38,6 +44,9 @@
3844
"jest":"^22.4.2"
3945
},
4046
"jest": {
41-
"testPathIgnorePatterns": ["/node_modules/","/fixtures/"]
47+
"testPathIgnorePatterns": [
48+
"/node_modules/",
49+
"/fixtures/"
50+
]
4251
}
4352
}

‎src/compiler.re‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,30 @@ module Stage = {
77
statements;
88
};
99
letparseTypescriptSource= (filename, source)=> {
10-
letlast5=String.sub(filename,String.length(filename)-5,5);
10+
letisDts=
11+
String.sub(filename,String.length(filename)-5,5)==".d.ts";
1112
letmodule_name=
12-
switch last5 {
13-
|".d.ts"=>String.sub(filename,0,String.length(filename)-5)
14-
|_=>String.sub(filename,0,String.length(filename)-3)
13+
if (isDts) {
14+
String.sub(filename,0,String.length(filename)-5);
15+
}else {
16+
String.sub(filename,0,String.length(filename)-3);
1517
};
1618
Typescript.parse(module_name, source);
1719
};
18-
letextension=String.sub(name,String.length(name)-3,3);
20+
letextension= {
21+
letparts=Js.String.split(".", name);
22+
parts[Array.length(parts)-1];
23+
};
1924
switch extension {
20-
|".js"=>
25+
|"js"=>
2126
parseFlowSource(name, source)|>List.map(FlowBsType.flowAstToBsTypeAst)
22-
|".ts"=>[
27+
|"ts"=>[
2328
parseTypescriptSource(name, source)
2429
|>TypescriptBsType.typescriptAstToBsTypeAst
2530
]
31+
|"graphql"=>[
32+
Graphql.parse(name, source)|>GraphqlBsType.graphqlAstToBsTypeAst
33+
]
2634
|_=>[]
2735
};
2836
};

‎src/graphqlBsType.re‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
lettypescriptAstToBsType=
2+
fun
3+
|_=>BsTypeAst.Any;
4+
5+
letrecgraphqlAstToBsTypeAst=
6+
fun
7+
|Graphql.Document(doc)=>
8+
BsTypeAst.ModuleDecl(
9+
"\""++Genutils.normalize_name(doc.loc.source.name)++"\"",
10+
doc.definitions|>Array.to_list|>List.map(graphqlAstToBsTypeAst)
11+
)
12+
|_=>BsTypeAst.Noop;

‎yarn.lock‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,12 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2:
16971697
version "4.1.11"
16981698
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
16991699

1700+
graphql@^0.13.2:
1701+
version "0.13.2"
1702+
resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.13.2.tgz#4c740ae3c222823e7004096f832e7b93b2108270"
1703+
dependencies:
1704+
iterall "^1.2.1"
1705+
17001706
growly@^1.3.0:
17011707
version "1.3.0"
17021708
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
@@ -2128,6 +2134,10 @@ istanbul-reports@^1.1.4:
21282134
dependencies:
21292135
handlebars "^4.0.3"
21302136

2137+
iterall@^1.2.1:
2138+
version "1.2.2"
2139+
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.2.2.tgz#92d70deb8028e0c39ff3164fdbf4d8b088130cd7"
2140+
21312141
jest-changed-files@^22.2.0:
21322142
version "22.2.0"
21332143
resolved "https://registry.yarnpkg.com/jest-changed-files/-/jest-changed-files-22.2.0.tgz#517610c4a8ca0925bdc88b0ca53bd678aa8d019e"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp