Skip to content

Exploring Mutate #84

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

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/content/markdown/authors/Adam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: Adam
friend: Amanda
enjoys:
- cats
- coding
- flatbread
---
7 changes: 7 additions & 0 deletions examples/content/markdown/authors/Amanda.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: Amanda
enjoys:
- cats
- coding
- flatbread
---
2 changes: 1 addition & 1 deletion examples/content/markdown/authors/daes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enjoys:
- cats
- coffee
- design
friend: 40s3
friend: Eva
date_joined: 2021-04-22T16:41:59.558Z
skills:
sitting: 304
Expand Down
2 changes: 1 addition & 1 deletion examples/content/markdown/authors/eva.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ enjoys:
- mow mow
- sleepy time
- attention
friend: 2a3e
friend: Tony
image: eva.svg
date_joined: 2002-02-25T16:41:59.558Z
skills:
Expand Down
2 changes: 1 addition & 1 deletion examples/content/markdown/authors/tony.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enjoys:
- cats
- tea
- making this
friend: 40s3
friend: Eva
image: tony.svg
date_joined: 2021-02-25T16:41:59.558Z
skills:
Expand Down
2 changes: 1 addition & 1 deletion examples/content/markdown/authors/yoshi.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ enjoys:
- encroaching upon personal space
- being concerned
- smooth jazz
friend: ab2c
friend: Daes
date_joined: 2018-10-25T16:23:59.558Z
skills:
sitting: 10
Expand Down
4 changes: 2 additions & 2 deletions examples/content/markdown/posts/anotha-one.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
id: 92348fds-453fdh-59ddsd-3332-09876
title: 'Test post A'
authors:
- 40s3
- 2a3e
- Eva
- Tony
rating: 84.3
---

Expand Down
4 changes: 2 additions & 2 deletions examples/content/markdown/posts/b.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
id: 2348fds-563fdh-59ddsd-3332-09876
title: 'Test post B'
authors:
- 1111
- ab2c
- Ushi
- Daes
rating: 44
---

Expand Down
4 changes: 2 additions & 2 deletions examples/content/markdown/posts/example-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
id: sdfsdf-23423-sdfsd-23444-dfghf
title: 'Example post of things'
authors:
- 2a3e
- 40s3
- Tony
- Eva
rating: 74
---

Expand Down
3 changes: 1 addition & 2 deletions examples/content/markdown/posts/soup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
id: jksfd4-234fdh-5345fj-3455-09836
title: 'Soup Reflection'
authors:
- r3c6
- ab2c
- Yoshi
rating: 96
---

Expand Down
6 changes: 3 additions & 3 deletions examples/nextjs/flatbread.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ export default defineConfig({
content: [
{
path: 'content/markdown/posts',
collection: 'Post',
name: 'Post',
refs: {
authors: 'Author',
},
},
{
path: 'content/markdown/posts/[category]/[slug].md',
collection: 'PostCategory',
name: 'PostCategory',
refs: {
authors: 'Author',
},
},
{
path: 'content/markdown/posts/**/*.md',
collection: 'PostCategoryBlob',
name: 'PostCategoryBlob',
refs: {
authors: 'Author',
},
Expand Down
20 changes: 6 additions & 14 deletions examples/sveltekit/flatbread.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,22 @@ export default defineConfig({
content: [
{
path: 'content/markdown/posts',
collection: 'Post',
name: 'Post',
refs: {
authors: 'Author',
},
},
{
path: 'content/markdown/posts/[category]/[slug].md',
collection: 'PostCategory',
refs: {
authors: 'Author',
},
},
{
path: 'content/markdown/posts/**/*.md',
collection: 'PostCategoryBlob',
name: 'PostCategory',
refs: {
authors: 'Author',
},
},
{
path: 'content/markdown/authors',
collection: 'Author',
name: 'Author',
referenceField: 'name',
refs: {
friend: 'Author',
},
Expand All @@ -54,20 +48,18 @@ export default defineConfig({
},
{
path: 'content/yaml/authors',
collection: 'YamlAuthor',
name: 'YamlAuthor',
refs: {
friend: 'YamlAuthor',
},
},
{
path: 'content/markdown/deeply-nested',
collection: 'OverrideTest',
name: 'OverrideTest',
overrides: [
{
field: 'deeply.nested',
type: 'String',
test: undefined,
test2: null,
resolve: (source) => String(source).toUpperCase(),
},
{
Expand Down
55 changes: 55 additions & 0 deletions examples/sveltekit/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<script lang="ts">
import { browser } from '$app/env';
import Pane from './../lib/components/Pane.svelte';

/** @type {import('./$types').PageData}*/
export let data;

if (browser) {
import('svimg/dist/s-image');
}

export let error = null;
if (error) console.error(error);

function joinAuthors(authors) {
return authors?.map((author) => author.name).join(', ');
}
</script>

<div class="grid grid-cols-2 divide-x-2 divide-black">
<Pane label="JSON Output">
<pre
class="overflow-auto p-3"
style="height: calc(100vh - 3.5rem);">
<code class="text-sm">
{JSON.stringify(data, null, 2)}
</code>
</pre>
</Pane>
<Pane label="Frontend">
{#each data.allPostCategories as post, _ (post.id)}
<article class="m-3 border border-opacity-20 bg-gray-50 p-3">
<h3 class="text-xl font-medium">{post.title}</h3>
<ul>
<li class="text-xs font-semibold text-gray-500">
<div class="flex">
{#each post.authors as author}
<div>
<div class="h-12 w-12">
<s-image {...author.image} />
</div>
{author.name}
</div>
{/each}
</div>
</li>
<li class="text-xs font-semibold text-gray-500">
Rating: {post.rating}
</li>
</ul>
<div>{@html post._content.html}</div>
</article>
{/each}
</Pane>
</div>
79 changes: 79 additions & 0 deletions examples/sveltekit/src/routes/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { error } from '@sveltejs/kit';

export const load = async ({ fetch }) => {
const query = `
query PostCategory {
allPostCategories (sortBy: "title", order: DESC) {
_metadata {
sourceContext {
filename
slug
}
collection
}
id
title
category
slug
rating
_content {
raw
html
excerpt
timeToRead
}
authors {
_metadata {
sourceContext {
slug
}
}
id
name
entity
enjoys
image {
srcset
srcsetwebp
srcsetavif
placeholder
aspectratio
}
friend {
name
date_joined
}
date_joined
skills {
sitting
breathing
liquid_consumption
existence
sports
}
}
}
}
`;

try {
const response = await fetch('http://localhost:5057/graphql', {
body: JSON.stringify({
query,
}),
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
method: 'POST',
});

const { data, errors } = await response.json();

if (errors)
throw error(500, errors.map(({ message }) => message).join('\\n'));
return data;
} catch (e) {
throw error(500, 'Failed to load data');
}
};
Loading