Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
23cca44
feat: add alias directive annotation
mjfwebb Jul 5, 2023
882fb13
feat: add queryOptions directive annotation
mjfwebb Jul 6, 2023
c8a70e1
feat: parse Kind.INT and Kind.Float into JS numbers
mjfwebb Jul 6, 2023
c77722c
feat: add default directive annotation
mjfwebb Jul 6, 2023
397bf91
feat: add coalesce directive annotation
mjfwebb Jul 6, 2023
fd8215a
feat: add customResolver annotation
mjfwebb Jul 6, 2023
cb0e091
feat: add ID directive annotation
mjfwebb Jul 6, 2023
112068d
refactor: use makeDirectiveNode in key-annotation tests
mjfwebb Jul 7, 2023
2fe13e8
feat: add mutation directive annotation
mjfwebb Jul 7, 2023
eb8fe97
feat: add plural directive annotation
mjfwebb Jul 7, 2023
c117e68
feat: add filterable directive annotation
mjfwebb Jul 7, 2023
904bfd9
feat: add fulltext directive annotation
mjfwebb Jul 7, 2023
0491346
feat: add node directive annotation
mjfwebb Jul 7, 2023
21220f3
feat: add populatedBy directive annotation
mjfwebb Jul 7, 2023
6f27b6a
feat: add query directive annotation
mjfwebb Jul 7, 2023
2df6ea3
feat: add private directive annotation
mjfwebb Jul 7, 2023
f2de8b6
feat: add relationshipProperties annotation
mjfwebb Jul 7, 2023
98f8054
feat: add selectable directive annotation
mjfwebb Jul 7, 2023
e61c0f3
feat: add settable directive annotation
mjfwebb Jul 7, 2023
e9e9bb5
feat: add timestamp directive annotation
mjfwebb Jul 7, 2023
4110b77
feat: add unique directive annotation
mjfwebb Jul 7, 2023
a2988ff
feat: add subscription directive annotation
mjfwebb Jul 7, 2023
ad8bb57
feat: add jwt-claim directive annotation
mjfwebb Jul 7, 2023
7a207d6
feat: add jwt-payload directive annotation
mjfwebb Jul 7, 2023
757fdbe
feat: add directives to Annotation
mjfwebb Jul 7, 2023
becc1f9
Merge branch 'schema-model-refactoring' into add-directive-annotations
MacondoExpress Jul 19, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { AliasAnnotation } from "./AliasAnnotation";

describe("AliasAnnotation", () => {
it("initialize class correctly when property param is set", () => {
const aliasAnnotation = new AliasAnnotation({
property: "test",
});
expect(aliasAnnotation.property).toBe("test");
});
});
26 changes: 26 additions & 0 deletions packages/graphql/src/schema-model/annotation/AliasAnnotation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export class AliasAnnotation {
public readonly property: string;

constructor({ property }: { property: string }) {
this.property = property;
}
}
112 changes: 111 additions & 1 deletion packages/graphql/src/schema-model/annotation/Annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,91 @@
* limitations under the License.
*/

import { AliasAnnotation } from "./AliasAnnotation";
import { AuthenticationAnnotation } from "./AuthenticationAnnotation";
import { AuthorizationAnnotation } from "./AuthorizationAnnotation";
import { CoalesceAnnotation } from "./CoalesceAnnotation";
import { CustomResolverAnnotation } from "./CustomResolverAnnotation";
import { CypherAnnotation } from "./CypherAnnotation";
import { DefaultAnnotation } from "./DefaultAnnotation";
import { FilterableAnnotation } from "./FilterableAnnotation";
import { FullTextAnnotation } from "./FullTextAnnotation";
import { IDAnnotation } from "./IDAnnotation";
import { JWTClaimAnnotation } from "./JWTClaimAnnotation";
import { JWTPayloadAnnotation } from "./JWTPayloadAnnotation";
import { KeyAnnotation } from "./KeyAnnotation";
import { MutationAnnotation } from "./MutationAnnotation";
import { NodeAnnotation } from "./NodeAnnotation";
import { PluralAnnotation } from "./PluralAnnotation";
import { PopulatedByAnnotation } from "./PopulatedByAnnotation";
import { PrivateAnnotation } from "./PrivateAnnotation";
import { QueryAnnotation } from "./QueryAnnotation";
import { QueryOptionsAnnotation } from "./QueryOptionsAnnotation";
import { RelationshipPropertiesAnnotation } from "./RelationshipPropertiesAnnotation";
import { SelectableAnnotation } from "./SelectableAnnotation";
import { SettableAnnotation } from "./SettableAnnotation";
import { SubscriptionAnnotation } from "./SubscriptionAnnotation";
import { SubscriptionsAuthorizationAnnotation } from "./SubscriptionsAuthorizationAnnotation";
import { TimestampAnnotation } from "./TimestampAnnotation";
import { UniqueAnnotation } from "./UniqueAnnotation";

export type Annotation =
| CypherAnnotation
| AuthorizationAnnotation
| AuthenticationAnnotation
| KeyAnnotation
| SubscriptionsAuthorizationAnnotation;
| SubscriptionsAuthorizationAnnotation
| AliasAnnotation
| QueryOptionsAnnotation
| DefaultAnnotation
| CoalesceAnnotation
| CustomResolverAnnotation
| IDAnnotation
| MutationAnnotation
| PluralAnnotation
| FilterableAnnotation
| FullTextAnnotation
| NodeAnnotation
| PopulatedByAnnotation
| QueryAnnotation
| PrivateAnnotation
| RelationshipPropertiesAnnotation
| SelectableAnnotation
| SettableAnnotation
| TimestampAnnotation
| UniqueAnnotation
| SubscriptionAnnotation
| JWTClaimAnnotation
| JWTPayloadAnnotation;

export enum AnnotationsKey {
cypher = "cypher",
authorization = "authorization",
authentication = "authentication",
key = "key",
subscriptionsAuthorization = "subscriptionsAuthorization",
alias = "alias",
queryOptions = "queryOptions",
default = "default",
coalesce = "coalesce",
customResolver = "customResolver",
id = "id",
mutation = "mutation",
plural = "plural",
filterable = "filterable",
fulltext = "fulltext",
node = "node",
populatedBy = "populatedBy",
query = "query",
private = "private",
relationshipProperties = "relationshipProperties",
selectable = "selectable",
settable = "settable",
timestamp = "timestamp",
unique = "unique",
subscription = "subscription",
jwtClaim = "jwtClaim",
jwtPayload = "jwtPayload",
}

export type Annotations = {
Expand All @@ -44,6 +110,28 @@ export type Annotations = {
[AnnotationsKey.authentication]: AuthenticationAnnotation;
[AnnotationsKey.key]: KeyAnnotation;
[AnnotationsKey.subscriptionsAuthorization]: SubscriptionsAuthorizationAnnotation;
[AnnotationsKey.alias]: AliasAnnotation;
[AnnotationsKey.queryOptions]: QueryOptionsAnnotation;
[AnnotationsKey.default]: DefaultAnnotation;
[AnnotationsKey.coalesce]: CoalesceAnnotation;
[AnnotationsKey.customResolver]: CustomResolverAnnotation;
[AnnotationsKey.id]: IDAnnotation;
[AnnotationsKey.mutation]: MutationAnnotation;
[AnnotationsKey.plural]: PluralAnnotation;
[AnnotationsKey.filterable]: FilterableAnnotation;
[AnnotationsKey.fulltext]: FullTextAnnotation;
[AnnotationsKey.node]: NodeAnnotation;
[AnnotationsKey.populatedBy]: PopulatedByAnnotation;
[AnnotationsKey.query]: QueryAnnotation;
[AnnotationsKey.private]: PrivateAnnotation;
[AnnotationsKey.relationshipProperties]: RelationshipPropertiesAnnotation;
[AnnotationsKey.selectable]: SelectableAnnotation;
[AnnotationsKey.settable]: SettableAnnotation;
[AnnotationsKey.timestamp]: TimestampAnnotation;
[AnnotationsKey.unique]: UniqueAnnotation;
[AnnotationsKey.subscription]: SubscriptionAnnotation;
[AnnotationsKey.jwtClaim]: JWTClaimAnnotation;
[AnnotationsKey.jwtPayload]: JWTPayloadAnnotation;
};

export function annotationToKey(ann: Annotation): keyof Annotations {
Expand All @@ -52,5 +140,27 @@ export function annotationToKey(ann: Annotation): keyof Annotations {
if (ann instanceof AuthenticationAnnotation) return AnnotationsKey.authentication;
if (ann instanceof KeyAnnotation) return AnnotationsKey.key;
if (ann instanceof SubscriptionsAuthorizationAnnotation) return AnnotationsKey.subscriptionsAuthorization;
if (ann instanceof AliasAnnotation) return AnnotationsKey.alias;
if (ann instanceof QueryOptionsAnnotation) return AnnotationsKey.queryOptions;
if (ann instanceof DefaultAnnotation) return AnnotationsKey.default;
if (ann instanceof CoalesceAnnotation) return AnnotationsKey.coalesce;
if (ann instanceof CustomResolverAnnotation) return AnnotationsKey.customResolver;
if (ann instanceof IDAnnotation) return AnnotationsKey.id;
if (ann instanceof MutationAnnotation) return AnnotationsKey.mutation;
if (ann instanceof PluralAnnotation) return AnnotationsKey.plural;
if (ann instanceof FilterableAnnotation) return AnnotationsKey.filterable;
if (ann instanceof FullTextAnnotation) return AnnotationsKey.fulltext;
if (ann instanceof NodeAnnotation) return AnnotationsKey.node;
if (ann instanceof PopulatedByAnnotation) return AnnotationsKey.populatedBy;
if (ann instanceof QueryAnnotation) return AnnotationsKey.query;
if (ann instanceof PrivateAnnotation) return AnnotationsKey.private;
if (ann instanceof RelationshipPropertiesAnnotation) return AnnotationsKey.relationshipProperties;
if (ann instanceof SelectableAnnotation) return AnnotationsKey.selectable;
if (ann instanceof SettableAnnotation) return AnnotationsKey.settable;
if (ann instanceof TimestampAnnotation) return AnnotationsKey.timestamp;
if (ann instanceof UniqueAnnotation) return AnnotationsKey.unique;
if (ann instanceof SubscriptionAnnotation) return AnnotationsKey.subscription;
if (ann instanceof JWTClaimAnnotation) return AnnotationsKey.jwtClaim;
if (ann instanceof JWTPayloadAnnotation) return AnnotationsKey.jwtPayload;
throw new Error("annotation not known");
}
28 changes: 28 additions & 0 deletions packages/graphql/src/schema-model/annotation/CoalesceAnnotation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export type CoalesceAnnotationValue = string | number | boolean;

export class CoalesceAnnotation {
public readonly value: CoalesceAnnotationValue;

constructor({ value }: { value: CoalesceAnnotationValue }) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export class CustomResolverAnnotation {
public readonly requires: string[];

constructor({ requires }: { requires: string[] }) {
this.requires = requires;
}
}
28 changes: 28 additions & 0 deletions packages/graphql/src/schema-model/annotation/DefaultAnnotation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export type DefaultAnnotationValue = string | number | boolean;

export class DefaultAnnotation {
public readonly value: DefaultAnnotationValue;

constructor({ value }: { value: DefaultAnnotationValue }) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export class FilterableAnnotation {
public readonly byValue: boolean;
public readonly byAnnotation: boolean;

constructor({ byValue, byAnnotation }: { byValue: boolean; byAnnotation: boolean }) {
this.byValue = byValue;
this.byAnnotation = byAnnotation;
}
}
33 changes: 33 additions & 0 deletions packages/graphql/src/schema-model/annotation/FullTextAnnotation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export type FullTextFields = {
name: string;
fields: string[];
queryName: string;
indexName: string;
};

export class FullTextAnnotation {
public readonly fields: FullTextFields;

constructor({ fields }: { fields: FullTextFields }) {
this.fields = fields;
}
}
30 changes: 30 additions & 0 deletions packages/graphql/src/schema-model/annotation/IDAnnotation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export class IDAnnotation {
public readonly autogenerate: boolean;
public readonly unique: boolean;
public readonly global: boolean;

constructor({ autogenerate, unique, global }: { autogenerate: boolean; unique: boolean; global: boolean }) {
this.autogenerate = autogenerate;
this.unique = unique;
this.global = global;
}
}
Loading