diff --git a/packages/graphql/src/index.ts b/packages/graphql/src/index.ts index 465ec689ca..9d41079c39 100644 --- a/packages/graphql/src/index.ts +++ b/packages/graphql/src/index.ts @@ -19,7 +19,6 @@ import { Neo4jGraphQL, Neo4jGraphQLConstructor } from "./classes"; import { Neo4jGraphQLContext } from "./types/neo4j-graphql-context"; - import * as directives from "./graphql/directives"; import { CartesianPoint } from "./graphql/objects/CartesianPoint"; import { Point } from "./graphql/objects/Point"; diff --git a/packages/graphql/src/schema/get-obj-field-meta.ts b/packages/graphql/src/schema/get-obj-field-meta.ts index 43167fc981..3e11e35606 100644 --- a/packages/graphql/src/schema/get-obj-field-meta.ts +++ b/packages/graphql/src/schema/get-obj-field-meta.ts @@ -170,8 +170,6 @@ function getObjFieldMeta({ "id", "authorization", "authentication", - "readonly", - "writeonly", "customResolver", "default", "coalesce", @@ -190,12 +188,6 @@ function getObjFieldMeta({ ), arguments: [...(field.arguments || [])], description: field.description?.value, - readonly: - directives.some((d) => d.name.value === "readonly") || - interfaceField?.directives?.some((x) => x.name.value === "readonly"), - writeonly: - directives.some((d) => d.name.value === "writeonly") || - interfaceField?.directives?.some((x) => x.name.value === "writeonly"), ...(unique ? { unique } : {}), }; diff --git a/packages/graphql/src/schema/to-compose.ts b/packages/graphql/src/schema/to-compose.ts index 3fc4958633..8b6ad6b456 100644 --- a/packages/graphql/src/schema/to-compose.ts +++ b/packages/graphql/src/schema/to-compose.ts @@ -17,7 +17,7 @@ * limitations under the License. */ -import type { DirectiveNode, InputValueDefinitionNode } from "graphql"; +import type { DirectiveNode } from "graphql"; import { GraphQLInt } from "graphql"; import type { Directive, @@ -33,27 +33,11 @@ import type { ConcreteEntityAdapter } from "../schema-model/entity/model-adapter import type { InterfaceEntityAdapter } from "../schema-model/entity/model-adapters/InterfaceEntityAdapter"; import { parseValueNode } from "../schema-model/parser/parse-value-node"; import { RelationshipAdapter } from "../schema-model/relationship/model-adapters/RelationshipAdapter"; -import type { BaseField, InputField, PrimitiveField, TemporalField } from "../types"; +import type { InputField } from "../types"; import { DEPRECATE_NOT } from "./constants"; -import getFieldTypeMeta from "./get-field-type-meta"; import { idResolver } from "./resolvers/field/id"; import { numericalResolver } from "./resolvers/field/numerical"; -export function graphqlInputValueToCompose(args: InputValueDefinitionNode[]) { - return args.reduce((res, arg) => { - const meta = getFieldTypeMeta(arg.type); - - return { - ...res, - [arg.name.value]: { - type: meta.pretty, - description: arg.description, - ...(arg.defaultValue ? { defaultValue: parseValueNode(arg.defaultValue) } : {}), - }, - }; - }, {}); -} - export function graphqlArgsToCompose(args: Argument[]) { return args.reduce((res, arg) => { const inputValueAdapter = new ArgumentAdapter(arg); @@ -81,40 +65,6 @@ export function graphqlDirectivesToCompose(directives: DirectiveNode[]): Directi })); } -export function objectFieldsToComposeFields(fields: BaseField[]): { - [k: string]: ObjectTypeComposerFieldConfigAsObjectDefinition; -} { - return fields.reduce((res, field) => { - if (field.writeonly || field.selectableOptions.onRead === false) { - return res; - } - - const newField: ObjectTypeComposerFieldConfigAsObjectDefinition = { - type: field.typeMeta.pretty, - args: {}, - description: field.description, - }; - - if (field.otherDirectives.length) { - newField.directives = graphqlDirectivesToCompose(field.otherDirectives); - } - - if (["Int", "Float"].includes(field.typeMeta.name)) { - newField.resolve = numericalResolver; - } - - if (field.typeMeta.name === "ID") { - newField.resolve = idResolver; - } - - if (field.arguments) { - newField.args = graphqlInputValueToCompose(field.arguments); - } - - return { ...res, [field.fieldName]: newField }; - }, {}); -} - export function relationshipAdapterToComposeFields( objectFields: RelationshipAdapter[], userDefinedFieldDirectives: Map @@ -334,6 +284,7 @@ export function withMathOperators(): AdditionalFieldsCallback { return fields; }; } + export function withArrayOperators(): AdditionalFieldsCallback { return (attribute: AttributeAdapter): InputTypeComposerFieldConfigMapDefinition => { const fields: InputTypeComposerFieldConfigMapDefinition = {}; diff --git a/packages/graphql/src/translate/projection/elements/create-relationship-property-value.test.ts b/packages/graphql/src/translate/projection/elements/create-relationship-property-value.test.ts index 2f8cbb36f9..b12c40de96 100644 --- a/packages/graphql/src/translate/projection/elements/create-relationship-property-value.test.ts +++ b/packages/graphql/src/translate/projection/elements/create-relationship-property-value.test.ts @@ -72,8 +72,6 @@ describe("createRelationshipPropertyElement", () => { otherDirectives: [], arguments: [], description: undefined, - readonly: false, - writeonly: false, } as PrimitiveField, ], pointFields: [ @@ -115,8 +113,6 @@ describe("createRelationshipPropertyElement", () => { otherDirectives: [], arguments: [], description: undefined, - readonly: false, - writeonly: false, } as PointField, ], temporalFields: [ @@ -158,8 +154,6 @@ describe("createRelationshipPropertyElement", () => { otherDirectives: [], arguments: [], description: undefined, - readonly: false, - writeonly: false, } as TemporalField, ], }); diff --git a/packages/graphql/src/types/index.ts b/packages/graphql/src/types/index.ts index 07eec2daf0..352731284c 100644 --- a/packages/graphql/src/types/index.ts +++ b/packages/graphql/src/types/index.ts @@ -113,8 +113,6 @@ export interface BaseField { arguments: InputValueDefinitionNode[]; private?: boolean; description?: string; - readonly?: boolean; - writeonly?: boolean; dbPropertyName?: string; dbPropertyNameUnescaped?: string; unique?: Unique; diff --git a/packages/ogm/src/utils/filter-document.test.ts b/packages/ogm/src/utils/filter-document.test.ts index ad66d007e9..786175db2f 100644 --- a/packages/ogm/src/utils/filter-document.test.ts +++ b/packages/ogm/src/utils/filter-document.test.ts @@ -23,13 +23,13 @@ import { filterDocument } from "./filter-document"; describe("filterDocument", () => { test("should remove all directives", () => { const initial = ` - type User @auth @exclude { - id: ID @auth @private @readonly @writeonly - name: String @auth @private @readonly @writeonly - email: String @auth @private @readonly @writeonly - password: String @auth @private @readonly @writeonly + type User @authentication @authorization { + id: ID @id @private @unique + name: String @authentication @authorization @private + email: String @cypher @private + password: String @private cars: [Car!]! @relationship(type: "HAS_CAR", direction: OUT, aggregate: false) - bikes: [Car!]! @relationship(type: "HAS_CAR", direction: OUT) + bikes: [Car!]! @relationship(type: "HAS_CAR", direction: OUT) } type Car @query(read: false, aggregate: false) @mutation(operations: []), @subscription(events: []) { @@ -50,9 +50,9 @@ describe("filterDocument", () => { expect(print(filtered)).toMatchInlineSnapshot(` "type User { - id: ID + id: ID @id @unique name: String - email: String + email: String @cypher password: String cars: [Car!]! @relationship(type: \\"HAS_CAR\\", direction: OUT, aggregate: true) bikes: [Car!]! @relationship(type: \\"HAS_CAR\\", direction: OUT, aggregate: true) diff --git a/packages/ogm/src/utils/filter-document.ts b/packages/ogm/src/utils/filter-document.ts index e09ac2cab4..5da26ac76d 100644 --- a/packages/ogm/src/utils/filter-document.ts +++ b/packages/ogm/src/utils/filter-document.ts @@ -22,14 +22,10 @@ import type { Neo4jGraphQLConstructor } from "@neo4j/graphql"; import { mergeTypeDefs } from "@graphql-tools/merge"; const excludedDirectives = [ - "auth", "authentication", "authorization", "subscriptionsAuthorization", - "exclude", "private", - "readonly", - "writeonly", "query", "mutation", "subscription", @@ -41,8 +37,8 @@ const excludedDirectives = [ export function filterDocument(typeDefs: Neo4jGraphQLConstructor["typeDefs"]): DocumentNode { // hack to keep aggregation enabled for OGM const schemaExtension = ` - extend schema @query(read: true, aggregate: true) - @mutation(operations: [CREATE, UPDATE, DELETE]) + extend schema @query(read: true, aggregate: true) + @mutation(operations: [CREATE, UPDATE, DELETE]) @subscription(events: [CREATED, UPDATED, DELETED, RELATIONSHIP_CREATED, RELATIONSHIP_DELETED])`; const merged = mergeTypeDefs( Array.isArray(typeDefs) ? (typeDefs as string[]).concat(schemaExtension) : [typeDefs as string, schemaExtension] diff --git a/packages/ogm/tests/integration/ogm.int.test.ts b/packages/ogm/tests/integration/ogm.int.test.ts index 391167307b..b36004ef7b 100644 --- a/packages/ogm/tests/integration/ogm.int.test.ts +++ b/packages/ogm/tests/integration/ogm.int.test.ts @@ -78,11 +78,11 @@ describe("OGM", () => { await session.close(); }); - test("should filter the document and remove directives such as auth", async () => { + test("should filter the document and remove directives such as authentication", async () => { const session = driver.session(); const typeDefs = ` - type ${typeMovie} @auth(rules: [{ isAuthenticated: true }]){ + type ${typeMovie} @authentication { id: ID } `;