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
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export interface PgType {
enumDescriptions: string[] | void;
rangeSubTypeId: string | void;
tags: { [tag: string]: true | string | Array<string> };
isFake?: boolean;
}

export interface PgAttribute {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export type PgType = {
enumDescriptions: ?(string[]),
rangeSubTypeId: ?string,
tags: { [string]: string },
isFake: ?boolean,
};

export type PgAttribute = {
Expand Down Expand Up @@ -714,9 +715,11 @@ Original error: ${e.message}

// Create fake enum type
const constraintIdent =
constraint.type === "p" ? "" : `_${constraint.name}`;
(constraint.type === "p" ? "" : `_${constraint.name}`) +
"_fake_enum";
const enumTypeArray = {
kind: "type",
isFake: true,
id: `FAKE_ENUM_${klass.namespaceName}_${klass.name}${constraintIdent}_list`,
name: `_${klass.name}${constraintIdent}`,
description: null,
Expand All @@ -739,6 +742,7 @@ Original error: ${e.message}
};
const enumType = {
kind: "type",
isFake: true,
id: `FAKE_ENUM_${klass.namespaceName}_${klass.name}${constraintIdent}`,
name: `${klass.name}${constraintIdent}`,
description: klass.description,
Expand Down
22 changes: 13 additions & 9 deletions packages/graphile-build-pg/src/plugins/PgTablesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ export default (function PgTablesPlugin(
const v = obj[fieldName];
if (inputField && v != null) {
const { type, typeModifier } = inputField;
return sql.fragment`${gql2pg(
v,
type,
typeModifier
)}::${sql.identifier(type.namespaceName, type.name)}`;
return sql.fragment`${gql2pg(v, type, typeModifier)}::${
type.isFake
? sql.identifier("unknown")
: sql.identifier(type.namespaceName, type.name)
}`;
} else {
return sql.null; // TODO: return default instead.
}
Expand All @@ -336,10 +336,14 @@ export default (function PgTablesPlugin(
return sql.fragment`row(${sql.join(
attributes.map(attr2sql),
","
)})::${sql.identifier(
tablePgType.namespaceName,
tablePgType.name
)}`;
)})::${
tablePgType.isFake
? sql.identifier("unknown")
: sql.identifier(
tablePgType.namespaceName,
tablePgType.name
)
}`;
},
};

Expand Down
8 changes: 5 additions & 3 deletions packages/graphile-build-pg/src/plugins/PgTypesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ export default (function PgTypesPlugin(
return sql.fragment`array[${sql.join(
val.map(v => gql2pg(v, type.arrayItemType, modifier)),
", "
)}]::${sql.identifier(type.namespaceName)}.${sql.identifier(
type.name
)}`;
)}]::${
type.isFake
? sql.identifier("unknown")
: sql.identifier(type.namespaceName, type.name)
}`;
} else {
return sql.value(val);
}
Expand Down
12 changes: 8 additions & 4 deletions packages/graphile-build-pg/src/plugins/viaTemporaryTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,14 @@ select ${sql.join(
(outputArgName, idx) =>
sql.query`(${sqlValuesAlias}.output_value_list)[${sql.literal(
idx + 1
)}]::${sql.identifier(
outputArgTypes[idx].namespaceName,
outputArgTypes[idx].name
)} as ${sql.identifier(
)}]::${
outputArgTypes[idx].isFake
? sql.identifier("unknown")
: sql.identifier(
outputArgTypes[idx].namespaceName,
outputArgTypes[idx].name
)
} as ${sql.identifier(
// According to https://www.postgresql.org/docs/10/static/sql-createfunction.html,
// "If you omit the name for an output argument, the system will choose a default column name."
// In PG 9.x and 10, the column names appear to be assigned with a `column` prefix.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ mutation {
description
}
}

referencingTableMutation(input: { t: { enum1: A1, enum2: B2, enum3: C4 } }) {
integer
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ Object {
"letter": "C",
},
},
"referencingTableMutation": Object {
"integer": 435,
},
},
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ type Mutation {
"""
input: DeleteReferencingTableByIdInput!
): DeleteReferencingTablePayload
referencingTableMutation(
"""
The exclusive input argument for this mutation. An object type, make sure to see documentation for this object’s fields.
"""
input: ReferencingTableMutationInput!
): ReferencingTableMutationPayload

"""
Updates a single \`LetterDescription\` using its globally unique id and a patch.
Expand Down Expand Up @@ -582,6 +588,31 @@ input ReferencingTableInput {
id: Int
}

"""All input for the \`referencingTableMutation\` mutation."""
input ReferencingTableMutationInput {
"""
An arbitrary string value with no semantic meaning. Will be included in the
payload verbatim. May be used to track mutations by the client.
"""
clientMutationId: String
t: ReferencingTableInput
}

"""The output of our \`referencingTableMutation\` mutation."""
type ReferencingTableMutationPayload {
"""
The exact same \`clientMutationId\` that was provided in the mutation input,
unchanged and unused. May be used by a client to track mutations.
"""
clientMutationId: String
integer: Int

"""
Our root query field type. Allows us to run any query from our mutation payload.
"""
query: Query
}

"""
Represents an update to a \`ReferencingTable\`. Fields that are set will be updated.
"""
Expand Down
12 changes: 12 additions & 0 deletions packages/postgraphile-core/__tests__/kitchen-sink-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,18 @@ create table enum_tables.referencing_table(
enum_3 char(2) references enum_tables.lots_of_enums(enum_3)
);

-- Relates to https://github.com/graphile/postgraphile/issues/1365
create function enum_tables.referencing_table_mutation(t enum_tables.referencing_table)
returns int as $$
declare
v_out int;
begin
insert into enum_tables.referencing_table (enum_1, enum_2, enum_3) values (t.enum_1, t.enum_2, t.enum_3)
returning id into v_out;
return v_out;
end;
$$ language plpgsql volatile;


--------------------------------------------------------------------------------

Expand Down