ce461aef34
refs 58b0a1b90d
- `buildQuery` in the post/page adapters was recently removed which meant it was falling back to the `EmbeddedRelationAdapter.buildQuery` method which uses the defined Ember Data relationships to build up an `?include=` param
- the Ember Data relationships are not fully in sync with the API because we don't have models for all of the members/tiers related relationships meaning we were adding a more restrictive `?include` parameter than what the API would use internally by default, breaking parts of the app that expected the default embedded relationships
50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
import ApplicationAdapter from 'ghost-admin/adapters/application';
|
|
|
|
export default class Post extends ApplicationAdapter {
|
|
buildIncludeURL(store, modelName, id, snapshot, requestType, query) {
|
|
const url = this.buildURL(modelName, id, snapshot, requestType, query);
|
|
const parsedUrl = new URL(url);
|
|
|
|
if (snapshot?.adapterOptions?.newsletter) {
|
|
const newsletter = snapshot.adapterOptions.newsletter;
|
|
parsedUrl.searchParams.append('newsletter', newsletter);
|
|
|
|
let emailSegment = snapshot?.adapterOptions?.emailSegment;
|
|
|
|
if (emailSegment) {
|
|
if (emailSegment === 'status:free,status:-free') {
|
|
emailSegment = 'all';
|
|
}
|
|
|
|
parsedUrl.searchParams.append('email_segment', emailSegment);
|
|
}
|
|
}
|
|
|
|
return parsedUrl.toString();
|
|
}
|
|
|
|
buildURL() {
|
|
const url = super.buildURL(...arguments);
|
|
|
|
try {
|
|
const parsedUrl = new URL(url);
|
|
if (!parsedUrl.searchParams.get('formats')) {
|
|
parsedUrl.searchParams.set('formats', 'mobiledoc,lexical');
|
|
return parsedUrl.href;
|
|
}
|
|
} catch (e) {
|
|
// noop, just use the original url
|
|
console.error('Couldn\'t parse URL', e); // eslint-disable-line
|
|
}
|
|
|
|
return url;
|
|
}
|
|
|
|
// posts and pages now include all relations by default so we don't want
|
|
// EmbeddedRelationAdapter.buildQuery adding an `?include=` param that
|
|
// overrides the defaults with a more restrictive list
|
|
buildQuery(store, modelName, options) {
|
|
return options;
|
|
}
|
|
}
|