Skip to content

Commit

Permalink
uda Ignore is no longer ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
burner committed Jan 24, 2020
1 parent b8aed6f commit a99ef1b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 45 deletions.
52 changes: 28 additions & 24 deletions source/graphql/schema/resolver.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ QueryResolver!(Con) buildTypeResolver(Type, Con)() {
}

GQLDSchema!(Type) toSchema(Type)() {
import graphql.uda : getUdaData, Ignore;
typeof(return) ret = new GQLDSchema!Type();

static foreach(qms; ["queryType", "mutationType", "subscriptionType"]) {{
Expand All @@ -46,30 +47,33 @@ GQLDSchema!(Type) toSchema(Type)() {
static if(__traits(hasMember, Type, qms)) {
alias QMSType = typeof(__traits(getMember, Type, qms));
static foreach(mem; __traits(allMembers, QMSType)) {{
alias MemType = typeof(__traits(getMember, QMSType, mem));
static if(isCallable!(MemType)) {{
GQLDOperation op = qms == "queryType"
? new GQLDQuery()
: qms == "mutationType" ? new GQLDMutation()
: qms == "subscriptionType" ? new GQLDSubscription()
: null;
cur.member[mem] = op;
assert(op !is null);
op.returnType = typeToGQLDType!(ReturnType!(MemType))(
ret
);

alias paraNames = ParameterIdentifierTuple!(
__traits(getMember, QMSType, mem)
);
alias paraTypes = Parameters!(
__traits(getMember, QMSType, mem)
);
static foreach(idx; 0 .. paraNames.length) {
op.parameters[paraNames[idx]] =
typeToGQLDType!(paraTypes[idx])(ret);
}
}}
enum uda = getUdaData!(QMSType, mem);
static if(uda.ignore != Ignore.yes) {
alias MemType = typeof(__traits(getMember, QMSType, mem));
static if(isCallable!(MemType)) {{
GQLDOperation op = qms == "queryType"
? new GQLDQuery()
: qms == "mutationType" ? new GQLDMutation()
: qms == "subscriptionType" ? new GQLDSubscription()
: null;
cur.member[mem] = op;
assert(op !is null);
op.returnType = typeToGQLDType!(ReturnType!(MemType))(
ret
);

alias paraNames = ParameterIdentifierTuple!(
__traits(getMember, QMSType, mem)
);
alias paraTypes = Parameters!(
__traits(getMember, QMSType, mem)
);
static foreach(idx; 0 .. paraNames.length) {
op.parameters[paraNames[idx]] =
typeToGQLDType!(paraTypes[idx])(ret);
}
}}
}
}}
}
}}
Expand Down
48 changes: 27 additions & 21 deletions source/graphql/schema/types.d
Original file line number Diff line number Diff line change
Expand Up @@ -601,10 +601,13 @@ GQLDType typeToGQLDType(Type, SCH)(ref SCH ret) {
alias fieldNames = FieldNameTuple!(Type);
alias fieldTypes = Fields!(Type);
static foreach(idx; 0 .. fieldNames.length) {{
static if(fieldNames[idx] != Constants.directives) {{
r.member[fieldNames[idx]] =
typeToGQLDType!(fieldTypes[idx])(ret);
}}
enum uda = getUdaData!(Type, fieldNames[idx]);
static if(uda.ignore != Ignore.yes) {
static if(fieldNames[idx] != Constants.directives) {{
r.member[fieldNames[idx]] =
typeToGQLDType!(fieldTypes[idx])(ret);
}}
}
}}

static if(is(Type == class)) {
Expand All @@ -622,24 +625,27 @@ GQLDType typeToGQLDType(Type, SCH)(ref SCH ret) {

static foreach(mem; __traits(allMembers, Type)) {
static if(!is(__traits(getMember, Type, mem))) {{ // not a type
enum uda = getUdaData!(Type, mem);
alias MemType = typeof(__traits(getMember, Type, mem));
static if(isCallable!MemType) {{
GQLDOperation op = new GQLDQuery();
r.member[mem] = op;
op.returnType =
typeToGQLDType!(ReturnType!(MemType))(ret);

alias paraNames = ParameterIdentifierTuple!(
__traits(getMember, Type, mem)
);
alias paraTypes = Parameters!(
__traits(getMember, Type, mem)
);
static foreach(idx; 0 .. paraNames.length) {
op.parameters[paraNames[idx]] =
typeToGQLDType!(paraTypes[idx])(ret);
}
}}
static if(uda.ignore != Ignore.yes) {
static if(isCallable!MemType) {{
GQLDOperation op = new GQLDQuery();
r.member[mem] = op;
op.returnType =
typeToGQLDType!(ReturnType!(MemType))(ret);

alias paraNames = ParameterIdentifierTuple!(
__traits(getMember, Type, mem)
);
alias paraTypes = Parameters!(
__traits(getMember, Type, mem)
);
static foreach(idx; 0 .. paraNames.length) {
op.parameters[paraNames[idx]] =
typeToGQLDType!(paraTypes[idx])(ret);
}
}}
}
}}
}
}
Expand Down
8 changes: 8 additions & 0 deletions source/graphql/testschema.d
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ struct Query {
Android[] resolverWillThrow();
GQLDCustomLeaf!(DateTime, dtToString) currentTime();
int currentTime();

@GQLDUda(Ignore.yes)
void ignoreMe() {
}
}

unittest {
Expand Down Expand Up @@ -118,6 +122,10 @@ class Humanoid : Character {

class Android : Character {
string primaryFunction;

@GQLDUda(Ignore.yes)
void ignoreMeToo() {
}
}

@GQLDUda(
Expand Down

1 comment on commit a99ef1b

@schveiguy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, I was just setting up to do something like this. Perfect.

Please sign in to comment.