Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@graphile-contrib/pg-dynamic-attributes
Advanced tools
PostGraphile plugin to fetch, order by and filter by dynamic attributes that are fetched from records in a related table at runtime.
This plugin enhances a PostGraphile schema with the ability to order by and filter by "dynamic attributes." For the purpose of this plugin "dynamic attributes" are stored into records in a related table and aren't known at schema build time.
Example database schema:
create table objects (
id serial primary key,
name text not null,
created_at timestamptz not null default now()
);
create table object_properties (
object_id int not null references objects on delete cascade,
attribute text not null,
value text not null,
primary key (object_id, attribute)
);
comment on table objects is E'@dynamicAttributes object_properties value';
This will add the Object.dynamicAttribute
field to your GraphQL schema for
fetching a dynamic attribute:
type Object {
# ...
"""
Fetches the dynamic attribute given the value of `attribute` for this
`Object`.
"""
dynamicAttribute(match: ObjectDynamicAttribute): String
}
It will also add a sort
argument to related connections so that you can order
by these attributes:
"""
When the given sortable is null, should we position this at the end of the list
or the beginning of the list?
"""
enum SortNulls {
"""
Order nulls last when in ascending order, or first when in descending order.
"""
DEFAULT
"""
Order nulls first (at the beginning of the list).
"""
FIRST
"""
Order nulls last (at the end of the list).
"""
LAST
}
"""
Sortable concrete fields for the `Object` type.
"""
enum ObjectSortableField {
ID
NAME
CREATED_AT
}
"""
Dynamic attribute keys for the `Object` type.
"""
input ObjectDynamicAttribute {
attribute: String!
}
"""
The specifier of what we should sort by. Exactly one of these values must be
specified and non-null (this will use `@oneOf`
[when that feature is merged into GraphQL](https://github.com/graphql/graphql-spec/pull/825)).
"""
input ObjectSortBy {
field: ObjectSortableField
dynamicAttribute: ObjectDynamicAttribute
}
"""
Specifies a sort for the `Object` type - what should we sort by, should it be
ascending or descending, and how should we handle nulls?
"""
input ObjectSort {
sortBy: ObjectSortBy!
ascending: Boolean! = true
nulls: SortNulls! = DEFAULT
}
type Query {
# ...
allObjects(
# ...
sort: [ObjectSort!]
): ObjectsConnection
}
If you are using
postgraphile-plugin-connection-filter
then we'll also add filters to this plugin under the dynamicAttribute
key:
{
allObjects(
filter: {
and: [
{
dynamicAttribute: {
match: {
attribute: "Attribute1"
}
filter: {
equalTo: "Value1"
}
}
},
{
dynamicAttribute: {
match: {
attribute: "Attribute2"
}
filter: {
equalTo: "Value2"
}
}
}
]
}
) {
# ...
}
}
We rely on the community's support to keep producing and maintaining OSS; if you find this plugin helpful, please click here to find out more about sponsors and sponsorship.
From the CLI you can install this plugin and run using command line
postgraphile
:
yarn add postgraphile @graphile-contrib/pg-dynamic-attributes
yarn postgraphile --append-plugins @graphile-contrib/pg-dynamic-attributes -c postgres://localhost/my_db
In library mode you can use appendPlugins
to install the plugin:
app.use(
postgraphile(process.env.DATABASE_URL, process.env.SCHEMA_NAME, {
appendPlugins: [require("@graphile-contrib/pg-dynamic-attributes")],
}),
);
The example assumes that your primary key contains all the required attributes;
however we can also support a unique constraint by passing its name as an
additional argument to the dynamicAttribute
smart comment:
create table objects (
id serial primary key,
name text not null,
created_at timestamptz not null default now()
);
create table object_properties (
id serial primary key,
object_id int not null references objects on delete cascade,
attribute text not null,
value text not null
);
alter table object_properties add constraint ak_object_properties_dynamic_attributes unique (object_id, attribute);
comment on table objects is E'@dynamicAttributes object_properties value ak_object_properties_dynamic_attributes';
Note: it's still critical that the first entry in the unique constraint is the column that references the parent table's primary key.
Experimental; the API may yet change.
This plugin was originally sponsored by Pixel Networks 🙌
FAQs
PostGraphile plugin to fetch, order by and filter by dynamic attributes that are fetched from records in a related table at runtime.
The npm package @graphile-contrib/pg-dynamic-attributes receives a total of 5 weekly downloads. As such, @graphile-contrib/pg-dynamic-attributes popularity was classified as not popular.
We found that @graphile-contrib/pg-dynamic-attributes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.