Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
56 changes: 27 additions & 29 deletions modules/ROOT/content-nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,36 @@
** xref:getting-started/index.adoc[]
*** xref:getting-started/toolbox.adoc[]

** Type definitions
*** xref:type-definitions/types/index.adoc[]
**** xref:type-definitions/types/scalar.adoc[Scalar]
**** xref:type-definitions/types/temporal.adoc[Temporal]
**** xref:type-definitions/types/spatial.adoc[Spatial]
**** xref:type-definitions/types/interfaces.adoc[Interface]
**** xref:type-definitions/types/unions.adoc[Union]
**** xref:type-definitions/types/relationships.adoc[]
*** xref:type-definitions/directives/index.adoc[]
**** xref:type-definitions/directives/basics.adoc[]
**** xref:type-definitions/directives/autogeneration.adoc[]
**** xref:type-definitions/directives/custom-directives.adoc[]
**** xref:type-definitions/directives/cypher.adoc[]
**** xref:type-definitions/directives/default-values.adoc[]
**** xref:type-definitions/directives/database-mapping.adoc[]
**** xref:type-definitions/directives/indexes-and-constraints.adoc[]

** xref:schema-configuration/index.adoc[Schema configuration]
*** xref:schema-configuration/type-configuration.adoc[]
*** xref:schema-configuration/global-configuration.adoc[]
*** xref:schema-configuration/field-configuration.adoc[]

** xref:queries-aggregations/index.adoc[Queries and aggregations]
*** xref:queries-aggregations/queries.adoc[]
*** xref:queries-aggregations/aggregations.adoc[]
*** xref:queries-aggregations/filtering.adoc[]
*** xref:queries-aggregations/sorting.adoc[]
*** xref:queries-aggregations/pagination/index.adoc[]
**** xref:queries-aggregations/pagination/offset-based.adoc[]
**** xref:queries-aggregations/pagination/cursor-based.adoc[]

** xref:mutations/index.adoc[]
*** xref:mutations/create.adoc[]
Expand All @@ -23,14 +48,11 @@

** xref:custom-resolvers.adoc[]

** xref:pagination/index.adoc[]
*** xref:pagination/offset-based.adoc[]
*** xref:pagination/cursor-based.adoc[]

** xref:authentication-and-authorization/index.adoc[]
*** xref:authentication-and-authorization/configuration.adoc[]
*** xref:authentication-and-authorization/authentication.adoc[]
*** xref:authentication-and-authorization/authorization.adoc[]
*** xref:authentication-and-authorization/impersonation-and-user-switching.adoc[]

** xref:introspector.adoc[Introspector]

Expand All @@ -50,31 +72,7 @@
*** xref:ogm/type-generation.adoc[]
*** xref:ogm/reference.adoc[]

** Reference
*** xref:reference/api-reference/index.adoc[]
**** xref:reference/api-reference/neo4jgraphql.adoc[]
**** xref:reference/api-reference/ogm.adoc[]
*** xref:reference/type-definitions/index.adoc[]
**** xref:reference/type-definitions/indexes-and-constraints.adoc[]
**** xref:reference/type-definitions/interfaces.adoc[]
**** xref:reference/type-definitions/relationships.adoc[]
**** xref:reference/type-definitions/types.adoc[]
**** xref:reference/type-definitions/unions.adoc[]

*** xref:reference/directives/index.adoc[]
**** xref:reference/directives/schema-configuration/index.adoc[]
***** xref:reference/directives/schema-configuration/type-configuration.adoc[]
***** xref:reference/directives/schema-configuration/global-configuration.adoc[]
***** xref:reference/directives/schema-configuration/field-configuration.adoc[]

**** xref:reference/directives/autogeneration.adoc[]
**** xref:reference/directives/basics.adoc[]
**** xref:reference/directives/custom-directives.adoc[]
**** xref:reference/directives/cypher.adoc[]
**** xref:reference/directives/default-values.adoc[]
**** xref:reference/directives/database-mapping.adoc[]

*** xref:reference/driver-configuration.adoc[]
*** xref:driver-configuration.adoc[]

** Frameworks and integrations
*** xref:integrations/apollo-federation.adoc[]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
= Impersonation and user switching

Impersonation and user switching are features of the Neo4j database and driver which allow for query execution in a different context to the initial connection.

== Impersonation

Impersonation still authenticates with the database as the original configured user, but runs the query in the context of an impersonated user.
When impersonating a user, the query is run within the complete security context of the impersonated user and not the authenticated user (home database, permissions, etc.).

An example of how to impersonate a different user per request can be found below. In this example, the user to impersonate is taken from a HTTP header `User`:

.TypeScript
[%collapsible]
====
[source, typescript, indent=0]
----
import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import { Neo4jGraphQL, Neo4jGraphQLContext } from "@neo4j/graphql";
import neo4j from "neo4j-driver";

const typeDefs = `#graphql
type Movie {
title: String!
}
`;

const driver = neo4j.driver(
"neo4j://localhost:7687",
neo4j.auth.basic("neo4j", "password")
);

const neo4jgraphql = new Neo4jGraphQL({
typeDefs,
driver,
});

const schema = await neo4jgraphql.getSchema();

const server = new ApolloServer<Neo4jGraphQLContext>({
schema,
});

const { url } = await startStandaloneServer(server, {
// Your async context function should async and return an object
context: async ({ req }) => ({
sessionConfig: {
impersonatedUser: req.headers.user,
},
}),
});

console.log(`🚀 Server ready at: ${url}`);
----
====

.JavaScript
[%collapsible]
====
[source, javascript, indent=0]
----
import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import { Neo4jGraphQL } from "@neo4j/graphql";
import neo4j from "neo4j-driver";

const typeDefs = `#graphql
type Movie {
title: String!
}
`;

const driver = neo4j.driver(
"neo4j://localhost:7687",
neo4j.auth.basic("neo4j", "password")
);

const neo4jgraphql = new Neo4jGraphQL({
typeDefs,
driver,
});

const schema = await neo4jgraphql.getSchema();

const server = new ApolloServer({
schema,
});

const { url } = await startStandaloneServer(server, {
// Your async context function should async and return an object
context: async ({ req }) => ({
sessionConfig: {
impersonatedUser: req.headers.user,
},
}),
});

console.log(`🚀 Server ready at: ${url}`);
----
====

== User switching

User switching completely switches the user authenticating with the database for the given session, without the performance cost of instantiating an entire new driver instance.

An example of configuring user switching on a per request basis can be found in the example below. Note that the username and password are provided in HTTP headers `User` and `Password`, but this would not be recommended for production use:

.TypeScript
[%collapsible]
====
[source, typescript, indent=0]
----
import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import { Neo4jGraphQL, Neo4jGraphQLContext } from "@neo4j/graphql";
import neo4j from "neo4j-driver";

const typeDefs = `#graphql
type Movie {
title: String!
}
`;

const driver = neo4j.driver(
"neo4j://localhost:7687",
neo4j.auth.basic("neo4j", "password")
);

const neo4jgraphql = new Neo4jGraphQL({
typeDefs,
driver,
});

const schema = await neo4jgraphql.getSchema();

const server = new ApolloServer<Neo4jGraphQLContext>({
schema,
});

const { url } = await startStandaloneServer(server, {
// Your async context function should async and return an object
context: async ({ req }) => ({
sessionConfig: {
auth: neo4j.auth.basic(req.headers.user, req.headers.password),
},
}),
});

console.log(`🚀 Server ready at: ${url}`);
----
====

.JavaScript
[%collapsible]
====
[source, javascript, indent=0]
----
import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import { Neo4jGraphQL } from "@neo4j/graphql";
import neo4j from "neo4j-driver";

const typeDefs = `#graphql
type Movie {
title: String!
}
`;

const driver = neo4j.driver(
"neo4j://localhost:7687",
neo4j.auth.basic("neo4j", "password")
);

const neo4jgraphql = new Neo4jGraphQL({
typeDefs,
driver,
});

const schema = await neo4jgraphql.getSchema();

const server = new ApolloServer({
schema,
});

const { url } = await startStandaloneServer(server, {
// Your async context function should async and return an object
context: async ({ req }) => ({
sessionConfig: {
auth: neo4j.auth.basic(req.headers.user, req.headers.password),
},
}),
});

console.log(`🚀 Server ready at: ${url}`);
----
====


10 changes: 5 additions & 5 deletions modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ It can generate an entire executable schema with all of the additional types nee
For every query and mutation that is executed against this generated schema, the Neo4j GraphQL Library generates a single Cypher query which is executed against the database. This eliminates the https://www.google.com/search?q=graphql+n%2B1[N+1 Problem], which can make GraphQL implementations slow and inefficient.

- Automatic generation of xref::queries-aggregations/queries.adoc[Queries] and xref::mutations/index.adoc[Mutations] for CRUD interactions.
- xref::reference/type-definitions/types.adoc[Types], including temporal and spatial.
- xref::/type-definitions/types/index.adoc[Types], including temporal and spatial.
- Support for both node and relationship properties.
- Extensibility through the xref::reference/directives/cypher.adoc[`@cypher` directive] and/or xref::custom-resolvers.adoc[Custom Resolvers].
- Extensibility through the xref::/type-definitions/directives/cypher.adoc[`@cypher` directive] and/or xref::custom-resolvers.adoc[Custom Resolvers].
- Extensive xref::queries-aggregations/filtering.adoc[Filtering] and xref::queries-aggregations/sorting.adoc[Sorting] options.
- Options for value xref::reference/directives/autogeneration.adoc[Autogeneration] and xref::reference/directives/default-values.adoc[Default Values].
- xref::pagination/index.adoc[Pagination] options.
- xref::authentication-and-authorization/index.adoc[Authentication and authorization options] and additional xref::reference/directives/schema-configuration/index.adoc[Schema Configuration].
- Options for value xref::/type-definitions/directives/autogeneration.adoc[Autogeneration] and xref::/type-definitions/directives/default-values.adoc[Default Values].
- xref::/queries-aggregations/pagination/index.adoc[Pagination] options.
- xref::authentication-and-authorization/index.adoc[Authentication and authorization options] and additional xref::schema-configuration/index.adoc[Schema Configuration].
- An xref::ogm/index.adoc[OGM] (Object Graph Mapper) for programmatic interaction with your GraphQL API.
- A xref::getting-started/toolbox.adoc[Toolbox] (UI) to experiment with your Neo4j GraphQL API on Neo4j Desktop.

Expand Down
24 changes: 12 additions & 12 deletions modules/ROOT/pages/migration/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type NameOfTypeToExclude @exclude {
name: String
}
----
For more information regarding the above used `@exclude` directive, see xref::reference/directives/schema-configuration/type-configuration.adoc#_exclude_deprecated[`@exclude`]
For more information regarding the above used `@exclude` directive, see xref::/schema-configuration/type-configuration.adoc#_exclude_deprecated[`@exclude`]

=== Database Configuration

Expand Down Expand Up @@ -153,7 +153,7 @@ server.listen().then(({ url }) => {
});
----

Database bookmarks are also supported. See xref::reference/driver-configuration.adoc[Driver Configuration] for more information.
Database bookmarks are also supported. See xref::driver-configuration.adoc[Driver Configuration] for more information.

[[migration-guide-type-definitions]]
== Type Definitions
Expand All @@ -173,7 +173,7 @@ Migrating this directive is trivial:

For example, `@relation(name: "ACTED_IN", direction: OUT)` becomes `@relationship(type: "ACTED_IN", direction: OUT)`.

See xref::reference/type-definitions/relationships.adoc[Relationships] for more information on relationships in `@neo4j/graphql`.
See xref::/type-definitions/types/relationships.adoc[Relationships] for more information on relationships in `@neo4j/graphql`.

==== Relationship Properties

Expand Down Expand Up @@ -226,13 +226,13 @@ And note the following changes to the two node types:

=== `@cypher`

No change. See xref::reference/directives/cypher.adoc[`@cypher` directive] for more details on this directive in `@neo4j/graphql`.
No change. See xref::/type-definitions/directives/cypher.adoc[`@cypher` directive] for more details on this directive in `@neo4j/graphql`.

==== `@neo4j_ignore`

`@neo4j/graphql` offers two directives for skipping autogeneration for specified types/fields:

* xref::reference/directives/schema-configuration/type-configuration.adoc#_exclude_deprecated[`@exclude`]: Skip generation of specified Query/Mutation fields for an object type
* xref::/schema-configuration/type-configuration.adoc#_exclude_deprecated[`@exclude`]: Skip generation of specified Query/Mutation fields for an object type
* xref::custom-resolvers.adoc#custom-resolver-directive[`@customResolver`]: Ignore a field, which will need custom logic for resolution

==== `@isAuthenticated`, `@hasRole` and `@hasScope`
Expand All @@ -245,7 +245,7 @@ Not supported at this time.

==== `@id`

There is an equivalent directive in the new library, but it does not work using database constraints as per the old library. See xref::reference/directives/autogeneration.adoc#type-definitions-autogeneration-id[`@id`].
There is an equivalent directive in the new library, but it does not work using database constraints as per the old library. See xref::/type-definitions/directives/autogeneration.adoc#type-definitions-autogeneration-id[`@id`].

==== `@unique`, `@index` and `@search`

Expand All @@ -255,7 +255,7 @@ These all relate to database indexes and constraints, which are not currently su

==== Scalar Types

Supported as you would expect, with additional xref::reference/type-definitions/types.adoc#type-definitions-types-bigint[`BigInt`] support for 64 bit integers.
Supported as you would expect, with additional xref::/type-definitions/types/scalar.adoc[`BigInt`] support for 64 bit integers.

==== Temporal Types (`DateTime`, `Date`)

Expand Down Expand Up @@ -285,14 +285,14 @@ Has become:

Due to the move to ISO 8601 strings, input types are no longer necessary for temporal instances, so `_Neo4jDateTimeInput` has become `DateTime` and `_Neo4jDateInput` has become `Date` for input.

See xref::reference/type-definitions/types.adoc#type-definitions-types-temporal[Temporal Types].
See xref::/type-definitions/types/temporal.adoc[Temporal Types].

==== Spatial Types

The single type in `neo4j-graphql-js`, `Point`, has been split out into two types:

* xref::reference/type-definitions/types.adoc#type-definitions-types-point[`Point`]
* xref::reference/type-definitions/types.adoc#type-definitions-types-cartesian-point[`CartesianPoint`]
* xref::/type-definitions/types/spatial.adoc#_point[`Point`]
* xref::/type-definitions/types/spatial.adoc#_cartesianpoint[`CartesianPoint`]

Correspondingly, `_Neo4jPointInput` has also been split out into two input types:

Expand All @@ -303,11 +303,11 @@ Using them in Queries and Mutations should feel remarkably similar.

==== Interface Types

Supported, queryable using inline fragments as per `neo4j-graphql-js`, but can also be created using Nested Mutations. See xref::reference/type-definitions/interfaces.adoc[Interfaces].
Supported, queryable using inline fragments as per `neo4j-graphql-js`, but can also be created using Nested Mutations. See xref::/type-definitions/types/interfaces.adoc[Interfaces].

==== Union Types

Supported, queryable using inline fragments as per `neo4j-graphql-js`, but can also be created using Nested Mutations. See xref::reference/type-definitions/unions.adoc#type-definitions-unions[Unions].
Supported, queryable using inline fragments as per `neo4j-graphql-js`, but can also be created using Nested Mutations. See xref::/type-definitions/types/unions.adoc#type-definitions-unions[Unions].

=== Fields

Expand Down
Loading