Skip to content

Commit

Permalink
Merge pull request #8 from panter/fix/fields-with-mandatory-args
Browse files Browse the repository at this point in the history
fix: don't try to fetch fields with mandatory args
  • Loading branch information
macrozone authored May 1, 2020
2 parents fe49bff + 2acb2e9 commit be9d54a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/dataprovider/generated/nexus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export interface NexusGenRootTypes {
gender?: NexusGenEnums['Gender'] | null; // Gender
id: string; // String!
lastName?: string | null; // String
logs: string[]; // [String!]!
yearOfBirth?: number | null; // Int
}
UserRole: { // root type
Expand Down Expand Up @@ -265,6 +266,7 @@ export interface NexusGenFieldTypes {
gender: NexusGenEnums['Gender'] | null; // Gender
id: string; // String!
lastName: string | null; // String
logs: string[]; // [String!]!
roles: NexusGenRootTypes['UserRole'][]; // [UserRole!]!
yearOfBirth: number | null; // Int
}
Expand Down Expand Up @@ -313,6 +315,10 @@ export interface NexusGenArgTypes {
}
}
User: {
logs: { // args
from: string; // String!
to: string; // String!
}
roles: { // args
after?: NexusGenInputs['UserRoleWhereUniqueInput'] | null; // UserRoleWhereUniqueInput
before?: NexusGenInputs['UserRoleWhereUniqueInput'] | null; // UserRoleWhereUniqueInput
Expand Down
1 change: 1 addition & 0 deletions packages/dataprovider/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type User {
gender: Gender
id: String!
lastName: String
logs(from: String!, to: String!): [String!]!
roles(after: UserRoleWhereUniqueInput, before: UserRoleWhereUniqueInput, first: Int, last: Int, skip: Int, where: UserRoleWhereInput): [UserRole!]!
yearOfBirth: Int
}
Expand Down
4 changes: 4 additions & 0 deletions packages/dataprovider/src/buildGqlQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export const buildFields = (introspectionResults: IntrospectionResult) => (
if (type.name.startsWith("_")) {
return acc;
}
// skip if the field has mandatory args
if (field.args.some((arg) => arg.type.kind === "NON_NULL")) {
return acc;
}

if (type.kind !== TypeKind.OBJECT) {
return [...acc, gqlTypes.field(gqlTypes.name(field.name))];
Expand Down
10 changes: 9 additions & 1 deletion packages/dataprovider/test-data/testSchema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeSchema, objectType } from "@nexus/schema";
import { makeSchema, objectType, stringArg } from "@nexus/schema";
import { nexusPrismaPlugin } from "nexus-prisma";
import { join } from "path";
import { addCrudResolvers } from "../../backend/src";
Expand All @@ -17,6 +17,14 @@ const User = objectType({
t.model.yearOfBirth();
t.model.roles({ filtering: true });
t.model.gender();
// add one field that needs arguments and therefore can't be used by react-admin
t.list.field("logs", {
type: "String",
args: {
from: stringArg({ required: true }),
to: stringArg({ required: true }),
},
});
},
});
const UserRole = objectType({
Expand Down

0 comments on commit be9d54a

Please sign in to comment.