outserv icon indicating copy to clipboard operation
outserv copied to clipboard

feat(posting): support lists

Open Schartey opened this issue 2 years ago • 0 comments

Problem

As mentioned in #20 Outserv currently does not support lists in accordance to the graphql spec. According to the spec data stored as List type should result in an ordered list, but is currently implemented as set.

Example Schema

type List {
    texts: [String!]!
}

Mutation

mutation {
	addList(input: {texts: ["test","test", "test2", "test2", "test2", "test"]}) {
		list {
			texts
		}
	}
}

Result

{
	"data": {
		"addList": {
			"list": [
			{
				"texts": [
					"test",
					"test2"
				]
			}
			]
		}
	}

Solution

Ideally we want to store data as lists by default and as set by using the @set directive.

The schema should then allow list manipulation through index and value. We would have to be able to forward the index through the pb.DirectedEdge. Examples mentioned in discord:

input UpdateFooInput {
  filter: FooFilter!
  set: FooPatchSet
  remove: FooPatchRemove
}
input FooPatchSet {
  bar: StringArraySet
}
input FooPatchRemove {
  bar: StringArrayRemove
}
input StringArraySet {
  exact: [String]
  append: [String]
  prepend: [String]
  replace: StringArrayReplacements
}
input StringArrayRemove {
  barIndexes: [Int]
  barValues: [String]
  bar: Boolean
}
input StringArrayReplacements {
  indexes: [Int]
  values: [String]
}

To support index manipulation we could reuse the @search directive. This will index the values of the list through predicate and id.

Todo List:

  • [x] Store as ordered list Added an index array to Postings. Duplicate entries will be kept in the same posting and an index will be added. The PostingList now has a property ListSize that tracks the size of the PostingList including duplicate entries.
  • [ ] @set directive and set support
  • [ ] Add list indexing
  • [ ] Add additional schema generation for sets and lists

Curl Examples

Add complete list:

curl --request POST \
  --url http://localhost:8080/graphql \
  --header 'Content-Type: application/json' \
  --data '{"query":"mutation {addList(input: {texts: [\"test\",\"test\", \"test2\", \"test2\", \"test2\", \"test\"]}) { list { texts }}}"}'

Please provide feedback if the way I solved this is adequate. You probably know better ways of supporting this.


This change is Reviewable

Schartey avatar Mar 21 '22 14:03 Schartey