mirror of
https://github.com/FranP-code/countries.git
synced 2025-10-13 00:02:15 +00:00
Use a netlify lambda for the API
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,2 @@
|
||||
.env
|
||||
node_modules
|
||||
.netlify
|
||||
|
||||
@@ -1,7 +1,51 @@
|
||||
import provinces from 'provinces';
|
||||
import {continents, countries, languages} from 'countries-list';
|
||||
const provinces = require('provinces');
|
||||
const {ApolloServer, gql} = require('apollo-server-lambda');
|
||||
const {continents, countries, languages} = require('countries-list');
|
||||
|
||||
export default {
|
||||
const typeDefs = gql`
|
||||
type Continent {
|
||||
code: String
|
||||
name: String
|
||||
countries: [Country]
|
||||
}
|
||||
|
||||
type Country {
|
||||
code: String
|
||||
name: String
|
||||
native: String
|
||||
phone: String
|
||||
continent: Continent
|
||||
currency: String
|
||||
languages: [Language]
|
||||
emoji: String
|
||||
emojiU: String
|
||||
states: [State]
|
||||
}
|
||||
|
||||
type State {
|
||||
code: String
|
||||
name: String
|
||||
country: Country
|
||||
}
|
||||
|
||||
type Language {
|
||||
code: String
|
||||
name: String
|
||||
native: String
|
||||
rtl: Int
|
||||
}
|
||||
|
||||
type Query {
|
||||
continents: [Continent]
|
||||
continent(code: String): Continent
|
||||
countries: [Country]
|
||||
country(code: String): Country
|
||||
languages: [Language]
|
||||
language(code: String): Language
|
||||
}
|
||||
`;
|
||||
|
||||
const resolvers = {
|
||||
Country: {
|
||||
continent({continent}) {
|
||||
return {
|
||||
@@ -81,3 +125,15 @@ export default {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const server = new ApolloServer({
|
||||
typeDefs,
|
||||
resolvers,
|
||||
introspection: true,
|
||||
playground: true,
|
||||
engine: {
|
||||
apiKey: process.env.ENGINE_API_KEY
|
||||
}
|
||||
});
|
||||
|
||||
exports.handler = server.createHandler();
|
||||
17
index.js
17
index.js
@@ -1,17 +0,0 @@
|
||||
import resolvers from './resolvers';
|
||||
import typeDefs from './schema';
|
||||
import {ApolloServer} from 'apollo-server';
|
||||
|
||||
const server = new ApolloServer({
|
||||
typeDefs,
|
||||
resolvers,
|
||||
introspection: true,
|
||||
playground: true,
|
||||
engine: {
|
||||
apiKey: process.env.ENGINE_API_KEY
|
||||
}
|
||||
});
|
||||
|
||||
server.listen({port: process.env.PORT}).then(({url}) => {
|
||||
console.log(`🚀 Server ready at ${url}`);
|
||||
});
|
||||
2
netlify.toml
Normal file
2
netlify.toml
Normal file
@@ -0,0 +1,2 @@
|
||||
[build]
|
||||
functions = "functions"
|
||||
3000
package-lock.json
generated
3000
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
16
package.json
16
package.json
@@ -1,27 +1,21 @@
|
||||
{
|
||||
"engines": {
|
||||
"node": "10"
|
||||
},
|
||||
"scripts": {
|
||||
"pretest": "eslint index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit",
|
||||
"start": "nodemon -r dotenv/config -r esm index.js"
|
||||
"pretest": "eslint functions",
|
||||
"test": "echo \"Error: no test specified\" && exit"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "@trevorblades"
|
||||
},
|
||||
"dependencies": {
|
||||
"apollo-server": "^2.7.0",
|
||||
"apollo-server-lambda": "^2.10.0",
|
||||
"countries-list": "^2.4.3",
|
||||
"esm": "^3.2.25",
|
||||
"graphql": "^14.4.2",
|
||||
"graphql": "^14.6.0",
|
||||
"provinces": "^1.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@trevorblades/eslint-config": "^7.0.1",
|
||||
"apollo": "^2.16.0",
|
||||
"dotenv": "^6.1.0",
|
||||
"eslint": "^6.2.1",
|
||||
"nodemon": "^1.18.7"
|
||||
"eslint": "^6.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
44
schema.js
44
schema.js
@@ -1,44 +0,0 @@
|
||||
import {gql} from 'apollo-server';
|
||||
|
||||
export default gql`
|
||||
type Continent {
|
||||
code: String
|
||||
name: String
|
||||
countries: [Country]
|
||||
}
|
||||
|
||||
type Country {
|
||||
code: String
|
||||
name: String
|
||||
native: String
|
||||
phone: String
|
||||
continent: Continent
|
||||
currency: String
|
||||
languages: [Language]
|
||||
emoji: String
|
||||
emojiU: String
|
||||
states: [State]
|
||||
}
|
||||
|
||||
type State {
|
||||
code: String
|
||||
name: String
|
||||
country: Country
|
||||
}
|
||||
|
||||
type Language {
|
||||
code: String
|
||||
name: String
|
||||
native: String
|
||||
rtl: Int
|
||||
}
|
||||
|
||||
type Query {
|
||||
continents: [Continent]
|
||||
continent(code: String): Continent
|
||||
countries: [Country]
|
||||
country(code: String): Country
|
||||
languages: [Language]
|
||||
language(code: String): Language
|
||||
}
|
||||
`;
|
||||
1
static/_redirects
Normal file
1
static/_redirects
Normal file
@@ -0,0 +1 @@
|
||||
/ /.netlify/functions/graphql
|
||||
Reference in New Issue
Block a user