Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema.Reference: Optional Query parameter #137

Open
smyrman opened this issue Sep 17, 2017 · 0 comments
Open

schema.Reference: Optional Query parameter #137

smyrman opened this issue Sep 17, 2017 · 0 comments

Comments

@smyrman
Copy link
Collaborator

smyrman commented Sep 17, 2017

It would be useful if we could extend the schema.Reference with an optional field Query query.Predicate that would allow us to specify restrictions on which items could legally be linked.

type Reference struct {
	Path string
	Query query.Predicate
}

Example (somewhere in Schema.Fields):

	"ingredient": {
		Validator: &schema.Reference(
			Path: "vegetables",
			Qurey: query.MustParsePredicate(`type: {$in: ["broccoli", "carrot"]}`),
		},
	},

In validation of a reference value, Query.Match() would be called on the payload of the linked resource.

Implementation

We have some options on how to implement this:

  1. Extend on the current ReferenceChecker interface to something like this:
type ReferenceChecker interface {
	ReferenceChecker(path string, query query.Predicate) FieldValidator
}
  1. Replace the interface with something that can return an implementation of the new query.Resource interface.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant