Skip to content

Commit

Permalink
add interface for node
Browse files Browse the repository at this point in the history
  • Loading branch information
arvitaly committed Mar 14, 2017
1 parent 3784fe6 commit fe9012d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion __tests__/__snapshots__/with-schema-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ Array [
},
],
"isConnection": false,
"isNode": true,
"isInterface": true,
"isNode": false,
"name": "node",
"node": Object {
"alias": null,
Expand Down
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class GraphQLFieldsInfo {
}
return viewerNode.fields[0].fields;
}
getNodeInterfaceFields() {
return this.getFields()[0].fields;
}
getQueryConnectionFields() {
const viewerNode = this.getFields().find((f) => f.name === "viewer");
if (!viewerNode) {
Expand Down Expand Up @@ -174,14 +177,18 @@ class GraphQLFieldsInfo {
const graphqlInfo = this.getInfoFromOutputType(graphqlField.type);
if (typeof (graphqlInfo) !== "undefined") {
const nodeInterface = this.getNodeInterface();
if (graphqlInfo.interfaces.find((i) => i === nodeInterface) || graphqlInfo.isInterface) {
if (graphqlInfo.isInterface) {
field.isInterface = true;
}
if (graphqlInfo.interfaces.find((i) => i === nodeInterface)) {
field.isNode = true;
}
field.isConnection = graphqlInfo.isConnection;
}
if (field.fields.length > 0) {
if (typeof (graphqlInfo) === "undefined") {
throw new Error("GraphQLFieldInfo::Invalid type for field `" + field.name + "`");
throw new Error("GraphQLFieldInfo::Invalid type for field `" + field.name + "`:`" +
graphqlField.type + "`");
}
if (graphqlInfo.isInterface) {
// search fragment for resolve type for interface (e.g. Node-interface)
Expand Down
13 changes: 10 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface Field {
args: g.GraphQLArgument[];
type?: g.GraphQLOutputType;
isFragment?: boolean;
isInterface?: boolean;
isNode: boolean;
node: g.SelectionNode;
isConnection: boolean;
Expand Down Expand Up @@ -36,6 +37,9 @@ export class GraphQLFieldsInfo {
}
return viewerNode.fields[0].fields;
}
public getNodeInterfaceFields() {
return this.getFields()[0].fields;
}
public getQueryConnectionFields() {
const viewerNode = this.getFields().find((f) => f.name === "viewer");
if (!viewerNode) {
Expand Down Expand Up @@ -145,7 +149,6 @@ export class GraphQLFieldsInfo {
isConnection: boolean;
isInterface: boolean;
} | undefined;

if (g.isCompositeType(type)) {
if (g.isAbstractType(type)) {
if (type instanceof g.GraphQLInterfaceType) {
Expand Down Expand Up @@ -192,15 +195,19 @@ export class GraphQLFieldsInfo {
const graphqlInfo = this.getInfoFromOutputType(graphqlField.type);
if (typeof (graphqlInfo) !== "undefined") {
const nodeInterface = this.getNodeInterface();
if (graphqlInfo.interfaces.find((i) => i === nodeInterface) || graphqlInfo.isInterface ) {
if (graphqlInfo.isInterface) {
field.isInterface = true;
}
if (graphqlInfo.interfaces.find((i) => i === nodeInterface)) {
field.isNode = true;
}
field.isConnection = graphqlInfo.isConnection;
}

if (field.fields.length > 0) {
if (typeof (graphqlInfo) === "undefined") {
throw new Error("GraphQLFieldInfo::Invalid type for field `" + field.name + "`");
throw new Error("GraphQLFieldInfo::Invalid type for field `" + field.name + "`:`" +
graphqlField.type + "`");
}
if (graphqlInfo.isInterface) {
// search fragment for resolve type for interface (e.g. Node-interface)
Expand Down

0 comments on commit fe9012d

Please sign in to comment.