change file structure

This commit is contained in:
2025-07-25 18:00:17 +09:00
parent 32cd5b9be8
commit b48464f5cf
42 changed files with 42968 additions and 28647 deletions

View File

@@ -0,0 +1,3 @@
const songlists = [];
export default songlists;

View File

@@ -0,0 +1,30 @@
import songlists from '../database/songlists';
const resolvers = {
Query: {
songs: () => songlists,
song: (_, { rank }) => {
return songlists.filter(song => song.rank === rank)[0];
}
},
Mutation: {
addSong: (_, { name, artist, album, img }) => {
if (songlists.find(song => song.name === name)) return null;
const newSong = {
id : songlists.length + 1,
rank: songlists.length + 1,
name: name,
artist: artist,
album: album,
img: img
};
songlists.push(newSong);
return newSong;
}
}
}
export default resolvers;

View File

@@ -0,0 +1,23 @@
import { gql } from 'apollo-server';
const typeDefs = gql`
type Song {
id : Int!
rank: Int!
name: String!
artist: String!
album: String!
img: String!
}
type Query {
songs: [Song!]!
song(id: Int!): Song
}
type Mutation {
addSong(name: String!, artist: String!, album: String!, img: String!): Song!
}
`;
export default typeDefs;

View File

@@ -0,0 +1,14 @@
import { ApolloServer } from 'apollo-server';
import resolvers from './graphql/resolvers';
import typeDefs from './graphql/typeDefs';
// ApolloServer는 스키마와 리졸버가 반드시 필요함
const server = new ApolloServer({
typeDefs,
resolvers
});
// listen 함수로 웹 서버 실행
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});