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

json:api: Provide for fetching custom resource URLs #878

Closed
bradjones1 opened this issue Aug 3, 2021 · 4 comments
Closed

json:api: Provide for fetching custom resource URLs #878

bradjones1 opened this issue Aug 3, 2021 · 4 comments

Comments

@bradjones1
Copy link
Contributor

Drupal's jsonapi_search_api module provides a pseudo-resource for a search index, e.g. backed by solr. It is queried pretty much like any other resource, but returns resource items that do not match the URL parameter. E.g., I have a search index at /jsonapi/index/primary, which returns resources of profile type.

At the moment there's no real straightforward method for querying this URL and then allowing orbit's json:api source to parse the response as, more or less, the same as if we had queried /jsonapi/profiles, for instance.

@bradjones1
Copy link
Contributor Author

I consulted @gabesullice on the phrasing and spec, he clarifies:

/index/primary is a collection resource backed by solr, it is queried like any other collection, but returns resource objects whose types don't correspond to the URL path
orbit shouldn't rely on the URL path to determine the types of resource object(s) in the response

@bradjones1
Copy link
Contributor Author

Actually, this might be possible by forcing the URL in the query option? Reading

https://github.com/orbitjs/orbit/pull/875/files#diff-79e53c6d865f379b3d7518342b25d299b8fa84a35d82f04009ad4b86e366a899R41

@bradjones1
Copy link
Contributor Author

Indeed this is possible by forcing the url. I plan to make some MRs against the new documentation (thank you) to help suss this out. That WIP blog post with changes in 0.17 was helpful.

    this.props.dataStore.query(q => q.findRecords('profile--dating'), {
      sources: {
        remote: {
          url: '/jsonapi/index/primary'
        }
      }
    });

@dgeb
Copy link
Member

dgeb commented Aug 4, 2021

@bradjones1 ah, glad you saw the WIP post.

You're right that this should be possible with the snippet you wrote or as follows:

    // general (instead of per-source) request options in a simple scenario in which only your remote source will interpret `url`
    this.props.dataStore.query(q => q.findRecords('profile--dating'), {
      url: '/jsonapi/index/primary'
    });

    // query expression options
    this.props.dataStore.query(q => q.findRecords('profile--dating').options({
      url: '/jsonapi/index/primary'
    });

Also experiment with the fullResponse: true option to get full details from a response, which might contain document level links for example.

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

No branches or pull requests

2 participants