forked from Hganavak/graphql-server-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapollo-fetch-test.js
61 lines (50 loc) · 1.25 KB
/
apollo-fetch-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// import ApolloClient from 'apollo-client';
// import { print } from 'graphql/language/printer';
const { ApolloServer, gql } = require('apollo-server');
const { createApolloFetch } = require('apollo-fetch');
const apolloFetch = createApolloFetch({
uri: 'https://api.spacex.land/graphql',
});
const tiesto = (stuff) => {
console.log(stuff)
}
// fetch({
// query: '{ launches { mission_name }}',
// }).then(res => {
// console.log(res.data);
// });
// // You can also easily pass variables for dynamic arguments
// fetch({
// query: `query PostsForAuthor($id: Int!) {
// author(id: $id) {
// firstName
// posts {
// title
// votes
// }
// }
// }`,
// variables: { id: 1 },
// }).then(res => {
// console.log(res.data);
// });
const typeDefs = gql`
type Rocket {
name: String
}
type Query {
Rockets: [Rocket]
}
`;
const resolvers = {
// Query: (req) => apolloFetch({...req, query: '{ rockets { name } }').then(res => console.log(res.data)),
Query: (req) => tiesto(hi)
};
const server = new ApolloServer({
typeDefs,
resolvers
})
// The 'listen' method launches a web server.
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});