Expose places over GraphQL
All checks were successful
Build and deploy Backend / build (push) Successful in 1m1s
All checks were successful
Build and deploy Backend / build (push) Successful in 1m1s
This commit is contained in:
37
src/graphql/places.ts
Normal file
37
src/graphql/places.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { prisma } from '../prisma.js';
|
||||||
|
|
||||||
|
function serializeVoiceExperience(
|
||||||
|
experience: Awaited<ReturnType<typeof prisma.voiceExperience.findMany>>[number],
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
...experience,
|
||||||
|
createdAt: experience.createdAt.toISOString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listPlaces() {
|
||||||
|
const places = await prisma.place.findMany({
|
||||||
|
include: {
|
||||||
|
experiences: {
|
||||||
|
orderBy: { createdAt: 'desc' },
|
||||||
|
take: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
orderBy: { updatedAt: 'desc' },
|
||||||
|
});
|
||||||
|
|
||||||
|
return places.map((place) => ({
|
||||||
|
...place,
|
||||||
|
experiences: place.experiences.map(serializeVoiceExperience),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listVoiceExperiences() {
|
||||||
|
const experiences = await prisma.voiceExperience.findMany({
|
||||||
|
include: { place: true },
|
||||||
|
orderBy: { createdAt: 'desc' },
|
||||||
|
take: 100,
|
||||||
|
});
|
||||||
|
|
||||||
|
return experiences.map(serializeVoiceExperience);
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { GraphQLJSONObject } from './scalars.js';
|
import { GraphQLJSONObject } from './scalars.js';
|
||||||
|
import { listPlaces, listVoiceExperiences } from './places.js';
|
||||||
import { createVoiceExperience } from './voice-experiences.js';
|
import { createVoiceExperience } from './voice-experiences.js';
|
||||||
|
|
||||||
export const schema = /* GraphQL */ `
|
export const schema = /* GraphQL */ `
|
||||||
@@ -19,6 +20,7 @@ export const schema = /* GraphQL */ `
|
|||||||
name: String!
|
name: String!
|
||||||
latitude: Float!
|
latitude: Float!
|
||||||
longitude: Float!
|
longitude: Float!
|
||||||
|
experiences: [VoiceExperience!]!
|
||||||
}
|
}
|
||||||
|
|
||||||
type VoiceExperience {
|
type VoiceExperience {
|
||||||
@@ -43,6 +45,8 @@ export const schema = /* GraphQL */ `
|
|||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
health: String!
|
health: String!
|
||||||
|
places: [Place!]!
|
||||||
|
voiceExperiences: [VoiceExperience!]!
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
@@ -54,6 +58,8 @@ export const resolvers = {
|
|||||||
JSON: GraphQLJSONObject,
|
JSON: GraphQLJSONObject,
|
||||||
Query: {
|
Query: {
|
||||||
health: () => 'ok',
|
health: () => 'ok',
|
||||||
|
places: () => listPlaces(),
|
||||||
|
voiceExperiences: () => listVoiceExperiences(),
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
createVoiceExperience: async (
|
createVoiceExperience: async (
|
||||||
|
|||||||
Reference in New Issue
Block a user