graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellNone
LanguageHaskell2010

Hasura.Backends.Postgres.Schema.OnConflict

Description

Postgres Schema OnConflict

This module contains the building blocks for parsing on_conflict clauses, which in the Postgres backend are used to implement upsert functionality. These are used by backendInsertParser to construct a postgres-specific schema parser for insert (and upsert) mutations.

Synopsis

Documentation

onConflictFieldParser :: forall pgKind r m n. (MonadBuildSchema ('Postgres pgKind) r m n, AggregationPredicatesSchema ('Postgres pgKind)) => SourceInfo ('Postgres pgKind) -> TableInfo ('Postgres pgKind) -> m (InputFieldsParser n (Maybe (OnConflictClause ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))) Source #

Parser for a field name on_conflict of type tablename_on_conflict.

The tablename_on_conflict object is used to generate the ON CONFLICT SQL clause, indicating what should be done if an insert raises a conflict.

The types ordinarily produced by this parser are only created if the table has unique or primary keys constraints.

If there are no columns for which the current role has update permissions, we must still accept an empty list for update_columns to support the "ON CONFLICT DO NOTHING" case. We do this by adding a placeholder value to the enum. See https://github.com/hasura/graphql-engine/issues/6804.

conflictObjectParser :: forall pgKind r m n. (MonadBuildSchema ('Postgres pgKind) r m n, AggregationPredicatesSchema ('Postgres pgKind)) => SourceInfo ('Postgres pgKind) -> TableInfo ('Postgres pgKind) -> Maybe (UpdPermInfo ('Postgres pgKind)) -> NonEmpty (UniqueConstraint ('Postgres pgKind)) -> m (Parser 'Input n (OnConflictClause ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))) Source #

Create a parser for the _on_conflict object of the given table.

conflictConstraint :: forall pgKind r m n. MonadBuildSchema ('Postgres pgKind) r m n => NonEmpty (UniqueConstraint ('Postgres pgKind)) -> SourceInfo ('Postgres pgKind) -> TableInfo ('Postgres pgKind) -> m (Parser 'Both n (UniqueConstraint ('Postgres pgKind))) Source #

Constructs a Parser for the name of the constraints on a given table.

The TableCoreInfo of a given table contains a list of unique or primary key constraints. Given the list of such constraints, this function creates a parser for an enum type that matches it. This function makes no attempt at de-duplicating contraint names, and assumes they are correct.

This function can fail if a constraint has a name that cannot be translated to a GraphQL name (see hasura/graphql-engine-mono#1748).