Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prisma update typegraphql #126

Merged
merged 8 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/dataprovider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,25 @@ const dataProvider = useDataProvider({
queryDialect: "typegraphql" // 👈
})
```

### override mutation operation names due to prisma versions breaking changes

Now you can override mutation calls with your prefixes

```ts
import { Options, makePrefixedFullName } from "@ra-data-prisma/dataprovider";

const options: Options = {
queryDialect: "typegraphql",
mutationOperationNames: {
typegraphql: {
[CREATE]: (resource: ResourceDataprovider) =>
makePrefixedFullName(`createOne${resource.name}`),
[UPDATE]: (resource: ResourceDataprovider) =>
makePrefixedFullName(`updateOne${resource.name}`),
[DELETE]: (resource: ResourceDataprovider) =>
makePrefixedFullName(`deleteOne${resource.name}`),
},
},
};
```
knapeto marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 7 additions & 4 deletions packages/dataprovider/src/buildVariables/buildVariables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ import {
DELETE,
GET_LIST,
GET_MANY,
GET_ONE,
GET_MANY_REFERENCE,
GET_ONE,
UPDATE,
} from "react-admin";
import { CustomizeInputData, OurOptions } from "../types";
import { IntrospectionResult, Resource } from "./../constants/interfaces";

import { NexusGenArgTypes } from "../../generated/nexus";
import { buildVariables } from "./";
import { IntrospectionResult, Resource } from "./../constants/interfaces";
import { getTestIntrospectionNexus } from "../testUtils/getTestIntrospection";
import { CustomizeInputData, OurOptions } from "../types";

describe("buildVariables", () => {
let testIntrospection: IntrospectionResult;
let testUserResource: Resource;
let testBlogPostCommentResource: Resource;
const options: OurOptions = {};
const options: OurOptions = {
queryDialect: "nexus-prisma",
};

beforeAll(async () => {
testIntrospection = await getTestIntrospectionNexus();
Expand Down
14 changes: 7 additions & 7 deletions packages/dataprovider/src/buildVariables/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { IntrospectionInputObjectType } from "graphql";
import isNil from "lodash/isNil";
import isObject from "lodash/isObject";

import {
CREATE,
DELETE,
Expand All @@ -11,11 +7,15 @@ import {
GET_ONE,
UPDATE,
} from "react-admin";
import { buildWhere } from "../buildWhere";
import { IntrospectionResult, Resource } from "../constants/interfaces";
import { CreateParams, buildData } from "./buildData";
import { FetchType, OurOptions } from "../types";
import { buildData, CreateParams } from "./buildData";
import { IntrospectionResult, Resource } from "../constants/interfaces";

import { IntrospectionInputObjectType } from "graphql";
import { buildOrderBy } from "./buildOrderBy";
import { buildWhere } from "../buildWhere";
import isNil from "lodash/isNil";
import isObject from "lodash/isObject";
knapeto marked this conversation as resolved.
Show resolved Hide resolved

export interface GetListParams {
filter: { [key: string]: any };
Expand Down
17 changes: 9 additions & 8 deletions packages/dataprovider/src/buildWhere.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import {
IntrospectionInputObjectType,
IntrospectionInputTypeRef,
} from "graphql";
import upperFirst from "lodash/upperFirst";
import isObject from "lodash/isObject";
import isArray from "lodash/isArray";
import isEmpty from "lodash/isEmpty";
import {
CheckComparisonQueryResult,
IntrospectionResult,
Resource,
} from "./constants/interfaces";
import {
IntrospectionInputObjectType,
IntrospectionInputTypeRef,
} from "graphql";

import { OurOptions } from "./types";
import isArray from "lodash/isArray";
import isEmpty from "lodash/isEmpty";
import isObject from "lodash/isObject";
import { sanitizeKey } from "./utils/sanitizeKey";
import upperFirst from "lodash/upperFirst";
knapeto marked this conversation as resolved.
Show resolved Hide resolved

const getStringFilter = (
key: string,
Expand Down
5 changes: 3 additions & 2 deletions packages/dataprovider/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import useDataProvider from "./useDataProvider";
import buildDataProvider from "./buildDataProvider";
import { makePrefixedFullName } from "./utils/makePrefixedFullName";
import useDataProvider from "./useDataProvider";
export * from "./types";

export { useDataProvider, buildDataProvider };
export { useDataProvider, buildDataProvider, makePrefixedFullName };

export default buildDataProvider;
5 changes: 3 additions & 2 deletions packages/dataprovider/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { DocumentNode } from "graphql";

import {
CREATE,
DELETE,
Expand All @@ -10,6 +8,8 @@ import {
UPDATE,
} from "react-admin";

import { DocumentNode } from "graphql";

knapeto marked this conversation as resolved.
Show resolved Hide resolved
export type WhiteListFragment = {
type: "whitelist";
fields: string[];
Expand Down Expand Up @@ -83,6 +83,7 @@ export type ConfigOptions = {
};
customizeInputData?: CustomizeInputData;
introspection?: IntrospectionOptions;
mutationOperationNames?: Partial<Record<QueryDialect, object>>;
knapeto marked this conversation as resolved.
Show resolved Hide resolved
};

export type FetchType =
Expand Down
8 changes: 5 additions & 3 deletions packages/dataprovider/src/utils/makeIntrospectionOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import camelCase from "lodash/camelCase";
import pluralize from "pluralize";
import {
CREATE,
DELETE,
Expand All @@ -9,9 +7,12 @@ import {
GET_ONE,
UPDATE,
} from "react-admin";
import { Resource } from "../constants/interfaces";
import { OurOptions, QueryDialect } from "../types";

import { Resource } from "../constants/interfaces";
import camelCase from "lodash/camelCase";
import { makePrefixedFullName } from "./makePrefixedFullName";
import pluralize from "pluralize";

export const makeIntrospectionOptions = (options: OurOptions) => {
const prefix = (s: string) => makePrefixedFullName(s, options?.aliasPrefix);
Expand All @@ -27,6 +28,7 @@ export const makeIntrospectionOptions = (options: OurOptions) => {
[UPDATE]: (resource: Resource) => prefix(`update${resource.name}`),
[DELETE]: (resource: Resource) => prefix(`delete${resource.name}`),
},
...options.mutationOperationNames,
};

return {
Expand Down