I am looking to do something similar to what is done in the graphql tutorial: https://graphql.org/learn/queries/#arguments
this is my schema
type Query{
author(id:Int!):author
authors:[author]
books:[book]
book(id:Int!):book
}
type author{
id:Int!
name:String
surname: String
}
enum currency{
EUR
US
}
type book{
id:Int!
title:String!
authors:[author]
published:String
price(unit: currency = EUR):Float
}
schema{
query:Query
}
i want to convert the Currency, but i dont know how i connect my function with this returned type, to return the converted value.
Full server.js
const express=require('express');
const axios = require('axios');
const express_graphql = require('express-graphql');
var {buildSchema} = require('graphql');
var schema = buildSchema(`
type Query{
author(id:Int!):author
authors:[author]
books:[book]
book(id:Int!):book
}
type author{
id:Int!
name:String
surname: String
}
enum currency{
EUR
US
}
type book{
id:Int!
title:String!
authors:[author]
published:String
price(unit: currency = EUR):Float
}
schema{
query:Query
}
`)
var getAuthors = function(args){
return axios.get('http://localhost:1234/Authors').then(res => res.data);
}
var getAuthor = function(args){
return axios.get('http://localhost:1234/Authors/'+args.id).then(res => res.data);
}
var getBooks = function(args){
return axios.get('http://localhost:4321/Books').then(res => res.data);
}
var getBook = function(args) {
return axios.get('http://localhost:4321/Books/'+args.id).then(res => res.data);
}
var root = {
author:getAuthor,
authors:getAuthors,
books:getBooks,
book:getBook
}
const app=express();
app.use('/graphql', express_graphql({
schema,
rootValue: root,
graphiql: true
}));
function convertCurrency(Eur, unit){
if(unit==="EUR"){
return Eur;
}
if(Unit === "US"){
return Eur * 1.11;
}
}
app.listen(8080, ()=>{
console.log('server is running on port 8080..')
})