public async Task <IdentityResult> DeleteAllowedGrantTypeToClientAsync(Neo4jIdentityServer4Client client,
                                                                               Neo4JIdentityServer4IdentityServer4GrantType identityServer4GrantType, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            identityServer4GrantType.ThrowIfNull(nameof(identityServer4GrantType));
            try
            {
                var cypher = $@"
                MATCH 
                    (client:{IdSrv4Client})
                    -[:{Neo4jConstants.Relationships.HasGrantType}]->
                    (allowedGT:{IdSrv4AllowedGrantType})
                WHERE client.ClientId = $p0 AND allowedGT.IdentityServer4GrantType = $p1 
                DETACH DELETE allowedGT";

                var result = await Session.RunAsync(cypher, Params.Create(client.ClientId, identityServer4GrantType.GrantType));
                await RaiseClientChangeEventAsync(client);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <IdentityResult> AddAllowedGrantTypeToClientAsync(
            Neo4jIdentityServer4Client client,
            Neo4JIdentityServer4IdentityServer4GrantType identityServer4GrantType,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            client.ThrowIfNull(nameof(client));
            identityServer4GrantType.ThrowIfNull(nameof(identityServer4GrantType));
            try
            {
                var cypher = $@"
                MATCH (client:{IdSrv4Client} {{ClientId: $p0}})
                CREATE UNIQUE(
                    (client)-[:{Neo4jConstants.Relationships.HasGrantType}]->
                    (:{IdSrv4AllowedGrantType} {"$p1".AsMapForNoNull(identityServer4GrantType)}))";


                var result = await Session.RunAsync(cypher, Params.Create(client.ClientId, identityServer4GrantType));
                await RaiseClientChangeEventAsync(client);

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <IdentityResult> CreateGrantTypeAsync(
            Neo4JIdentityServer4IdentityServer4GrantType identityServer4GrantType,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            identityServer4GrantType.ThrowIfNull(nameof(identityServer4GrantType));
            try
            {
                var cypher = $@"CREATE (r:{IdSrv4GrantType} $p0)";
                await Session.RunAsync(cypher, Params.Create(identityServer4GrantType.ConvertToMap()));

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }
        public async Task <Neo4JIdentityServer4IdentityServer4GrantType> FindGrantTypeAsync(
            Neo4JIdentityServer4IdentityServer4GrantType identityServer4GrantType,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            identityServer4GrantType.ThrowIfNull(nameof(identityServer4GrantType));

            var cypher = $@"
                MATCH (r:{IdSrv4GrantType})
                WHERE r.GrantType = $p0
                RETURN r {{ .* }}";

            var result = await Session.RunAsync(cypher, Params.Create(identityServer4GrantType.GrantType));

            var grantTypeRecord =
                await result.SingleOrDefaultAsync(r => r.MapTo <Neo4JIdentityServer4IdentityServer4GrantType>("r"));

            return(grantTypeRecord);
        }
        public async Task <IdentityResult> DeleteGrantTypeAsync(
            Neo4JIdentityServer4IdentityServer4GrantType identityServer4GrantType,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            identityServer4GrantType.ThrowIfNull(nameof(identityServer4GrantType));
            try
            {
                var cypher = $@"
                MATCH (r:{IdSrv4GrantType})
                WHERE r.GrantType = $p0
                DETACH DELETE r";

                await Session.RunAsync(cypher, Params.Create(identityServer4GrantType.GrantType));

                return(IdentityResult.Success);
            }
            catch (ClientException ex)
            {
                return(ex.ToIdentityResult());
            }
        }