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

Federated query validation error messages #621

Merged
merged 7 commits into from
Oct 27, 2023

Conversation

mpoffald
Copy link
Contributor

@mpoffald mpoffald commented Oct 27, 2023

  • Adds some additional :error/messages to accommodate changes from Feature/federated queries #606
  • updates Malli to a version that has a recent fix for an error utility fn we use
  • Some errors since the schema change are showing up with nil values, this tweaks the logic used to extract the value so that the "Provided: <value>" portion of the error doesn't print nils

In general, as a consequence of expanding ::where-map by using a disjunction, some of our where clause errors aren't as specific as they could be. I have some ideas for how to fix that, but since fql schema is going to change again soon with new where syntax, it's better to hold off for now. This is just the low-hanging fruit that was available.

Examples of validation errors with these changes:

  ;; graph map  missing a where key
  (syntax/coerce-query '{"@context" "https://schema.org"
                         :from-named ["test/authors" "test/books" "test/movies"]
                         :select    [?movieName ?bookIsbn ?authorName]
                         :where     [{:graph "test/movies"}]})
;;=>
 ;; Error in value for "where"; where clauses must be valid tuples or maps;
 ;;  Invalid where map, must be either named graph or valid where operation map;
 ;;  Provided: {:graph "test/movies"}; See documentation for details:
 ;;  https://next.developers.flur.ee/docs/reference/errorcodes#query-invalid-where

  ;; graph map  w/ invalid where clause
  (syntax/coerce-query '{"@context" "https://schema.org"
                         :from-named ["test/authors" "test/books" "test/movies"]
                         :select    [?movieName ?bookIsbn ?authorName]
                         :where     [{:graph "test/authors"
                                      ;; invalid where
                                      :where [?author "name" ?authorName]}]})
;;=>
 ;;  Error in value for "where"; where clauses must be valid tuples or maps;
 ;;  Invalid where map, must be either named graph or valid where operation map;
 ;;  Provided: {:graph "test/authors", :where [?author "name" ?authorName]}; See
 ;;  documentation for details:
 ;;  https://next.developers.flur.ee/docs/reference/errorcodes#query-invalid-where
 

  ;;invalid value in `:from` vector
  (syntax/coerce-query '{"@context" "https://schema.org"
                         :from      [2]
                         :select    [?movieName ?bookIsbn ?authorName]
                         :where     [[?movie "type" "Movie"]
                                     [?movie "name" ?movieName]
                                     [?movie "isBasedOn" ?book]
                                     [?book "isbn" ?bookIsbn]
                                     [?book "author" ?author]
                                     [?author "name" ?authorName]]})
;;=>
 ;;  Error in value for "from"; invalid iri; Provided: 2; See documentation for
 ;;  details:
 ;;  https://next.developers.flur.ee/docs/reference/errorcodes#query-invalid-from

  ;;another invalid value for `:from`
  (syntax/coerce-query '{"@context" "https://schema.org"
                         :from      2
                         :select    [?movieName ?bookIsbn ?authorName]
                         :where     [[?movie "type" "Movie"]
                                     [?movie "name" ?movieName]
                                     [?movie "isBasedOn" ?book]
                                     [?book "isbn" ?bookIsbn]
                                     [?book "author" ?author]
                                     [?author "name" ?authorName]]})
;;=>
 ;;  Error in value for "from"; from must be a ledger iri or vector of ledger
 ;;  iris; Provided: 2; See documentation for details:
 ;;  https://next.developers.flur.ee/docs/reference/errorcodes#query-invalid-from


  ;; invalid value for `:graph` key:
  (syntax/coerce-query '{"@context" "https://schema.org"
                         :from-named ["test/authors" "test/books" "test/movies"]
                         :select    [?movieName ?bookIsbn ?authorName]
                         :where     [{:graph 2
                                      :where [[?movie "type" "Movie"]
                                              [?movie "name" ?movieName]
                                              [?movie "isBasedOn" ?book]]}]})
;;=>
 ;;  Error in value for "where"; Value of "graph" should be ledger alias or
 ;;  variable; Provided: 2; See documentation for details:
 ;;  https://next.developers.flur.ee/docs/reference/errorcodes#query-invalid-where

@mpoffald mpoffald requested a review from a team October 27, 2023 01:46
@mpoffald mpoffald force-pushed the update/federated-query-validation-errors branch from 6c4a47d to f1ffdaf Compare October 27, 2023 02:03
Copy link
Contributor

@cap10morgan cap10morgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One clarifying question but looks good overall

src/fluree/db/query/fql/syntax.cljc Show resolved Hide resolved
@mpoffald mpoffald merged commit 310e71e into main Oct 27, 2023
5 checks passed
@mpoffald mpoffald deleted the update/federated-query-validation-errors branch October 27, 2023 17:40
mpoffald added a commit to fluree/server that referenced this pull request Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants