Array field type(s)
See original GitHub issueAll DB platforms we’re planning to support in the near-term (eg. Mongo, pgSQL) support storing an ordered series of values in a single field. In both cases, the values stored can be of (almost) any other type supported by the data layer.
There are two way we could map this of thought on how these values should be typed:
A) Multiple array types with a different one for each underlying type (“TextArray”, “NumberArray”, “FileArray”, … ), eg…
keystone.createList('Post', {
fields: {
// ..
tags: { type: TextArray },
},
});
B) A single array type which is supplied an “inner type” when configured, eg…
keystone.createList('Post', {
fields: {
// ..
tags: { type: Array, ofType: Text },
},
});
We also need to make some decisions about how these values are accessed via GraphQL. OpenCRUD has some filters defined (field_contains
, field_contains_every
, field_contains_some
) but is missing others (field_not_contains
, field_contains_none
). Issues #87 and #217 have some relevant discussion.
@JedWatson leans fairly strongly towards building separate array types initially (option “A” above) with the focus on reusing components from the “inner” type where relevant. He’s suspects there are significant (enough) differences for how the interface will want to deal with a single value -vs- an array of values in the admin UI that going “fully generic” from the start won’t work well.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:11 (7 by maintainers)
Top GitHub Comments
The current workaround is to create a
Relationship
to another list:Then the graphQL query is:
And you can also look up all posts for a given tag:
Ideally, any nested ‘Array’ type would support a similar GraphQL API.
You should be able to create an intermediate list which contains the sort index:
Then you can retrieve an ordered list like so:
Note that the
.sortOrderForPost
field needs to be managed manually by you.