This commit is contained in:
2025-06-23 21:09:25 +09:00
commit 32cd5b9be8
50 changed files with 59220 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
// .babelrc
{
"presets" : ["@babel/preset-env"]
}

View File

@@ -0,0 +1,21 @@
{
"name": "FloChartAPIServer",
"version": "1.0.0",
"description": "FloChart-API-Server",
"main": "index.js",
"license": "MIT",
"dependencies": {
"apollo-server": "^2.17.0",
"axios": "^0.20.0",
"graphql": "^15.3.0"
},
"scripts": {
"start": "nodemon --exec babel-node src/index.js"
},
"devDependencies": {
"@babel/core": "^7.11.6",
"@babel/node": "^7.10.5",
"@babel/preset-env": "^7.11.5",
"nodemon": "^2.0.4"
}
}

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}`);
});

3288
FloChartAPIServer/yarn.lock Normal file

File diff suppressed because it is too large Load Diff