Here we can see the alternative solutions to prevent request URI too long / large (414 code)
Last active
March 18, 2025 19:32
-
-
Save joselcvarela/d8b7e57151c257a356a29281e07ba696 to your computer and use it in GitHub Desktop.
Directus: Prevent URI too large
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | |
}, | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} | |
} | |
`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.