Skip to content

Instantly share code, notes, and snippets.

@joselcvarela
Last active March 18, 2025 19:32
Show Gist options
  • Save joselcvarela/d8b7e57151c257a356a29281e07ba696 to your computer and use it in GitHub Desktop.
Save joselcvarela/d8b7e57151c257a356a29281e07ba696 to your computer and use it in GitHub Desktop.
Directus: Prevent URI too large

Here we can see the alternative solutions to prevent request URI too long / large (414 code)

fetch("https://directus.pizza/graphql", {
method: "POST",
body: JSON.stringify({
query: `query {
articles(filter: { categories: { categories_id: { title: { _icontains: "category" } } } }) {
id
title
sort
categories {
categories_id {
title
}
}
}
}`,
variables: {},
}),
headers: {
"Content-Type": "application/json",
Authorization: "Bearer mytoken",
},
});
import { createDirectus, graphql } from '@directus/sdk';
interface Category {
title: string;
}
interface ArticlesCategories {
categories_id: Category;
}
interface Article {
id: number;
title: string;
sort: number;
categories: ArticlesCategories[];
}
interface Schema {
articles: Article[];
}
const client = createDirectus<Schema>('https://directus.pizza').with(graphql());
const result = await client.query<Article[]>(`
query {
articles(filter: { categories: { categories_id: { title: { _icontains: "category" } } } }) {
id
title
sort
categories {
categories_id {
title
}
}
}
}
`);
fetch("https://directus.pizza/items/articles", {
method: "SEARCH",
body: JSON.stringify({
query: {
fields: ["id", "title", "sort", "categories.categories_id.title"],
filter: {
categories: {
categories_id: {
title: {
_icontains: "category",
},
},
},
},
},
}),
headers: {
"Content-Type": "application/json",
Authorization: "Bearer mytoken",
},
});

Comments are disabled for this gist.