-
Notifications
You must be signed in to change notification settings - Fork 0
Instrument Library API (Grapql)
This project is a GraphQL cloud service implemented in Node.js. It facilitates the buying and selling of musical instruments through posts. Users can create selling posts with details about the instrument they want to sell, and potential buyers can query and filter posts to find instruments of interest.
The service utilizes Apollo Server for GraphQL implementation and leverages GraphQL's flexibility in querying specific data needs. The underlying data is managed through resolvers, providing efficient data retrieval.
Apollo Server is a community-driven, open-source GraphQL server that works with any GraphQL schema. It simplifies the process of building GraphQL servers.
graphql is a query language for APIs and a runtime for executing those queries against your data. It allows clients to request only the data they need, providing a more efficient and flexible alternative to traditional REST APIs.
Before running the server, make sure to install the necessary dependencies using the following command:
npm install
Start the server by running the following command:
npm start
The server will be accessible at the specified address (standard http://localhost:4000). You can use tools like Apollo Playground or Rested to interact with the GraphQL API
get all stored instrument posts
query {
instrumentPosts {
// Fields to retrieve
}
}
get all stored instrument types
query {
instrumentTypes {
// Fields to retrieve
}
}
get all stored locations
query {
locations {
// Fields to retrieve
}
}
Get an instrument post by its unique ID.
query {
instrumentPostwithID(id: "uniqueID") {
// Fields to retrieve
}
}
Filter instrument posts based on specified criteria.
query {
filterInstrumentPosts(
sellerUserName: "username"
instrumentType: "type"
instrumentFamily: STRING
locationName: "location"
condition: NEW
priceMin: 100
priceMax: 500
) {
// Fields to retrieve
}
}
Filter instrument types based on the instrument family.
query {
filterInstrumentTypes(instrumentFamily: STRING) {
// Fields to retrieve
}
}
Create a new instrument post.
mutation {
createInstrumentPost(
title: "Title"
description: "Description"
imageUrl: "Image URL"
type: "Type"
age: 3
condition: NEW
price: 300.5
location: { city: "City" }
seller: { userID: 1, userName: "Username", email: "user@example.com" }
) {
// Fields to retrieve
}
}
Delete an instrument post by its ID.
mutation {
deleteInstrumentPost(postID: 1) {
// Fields to retrieve
}
}
type User {
userID: Int!
userName: String!
email: String!
instrumentsForSale: [InstrumentPost]!
}
input UserInput {
userID: Int!
userName: String!
email: String!
}
type InstrumentPost {
id: ID!
title: String!
description: String!
imageUrl: String!
type: InstrumentType!
age: Int!
condition: InstrumentCondition!
price: Float!
location: Location!
seller: User!
}
type Location {
city: String!
instrumentsForSale: [InstrumentPost]!
}
input LocationInput {
city: String!
}
type InstrumentType {
name: String!
family: InstrumentFamily!
instrumentsForSale: [InstrumentPost]!
}
enum InstrumentFamily {
Strings
Woodwind
Brass
Percussion
Electronic
}
enum InstrumentCondition {
NEW
USED
OLD
}