-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(test): make the gql api/client a fixture
- Loading branch information
Showing
5 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"use strict"; | ||
// Using the example graphql api here: https://www.apollographql.com/blog/graphql/examples/building-a-graphql-api/ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const server_1 = require("@apollo/server"); | ||
const graphql_tag_1 = __importDefault(require("graphql-tag")); | ||
const { startStandaloneServer } = require('@apollo/server/standalone'); | ||
// A schema is a collection of type definitions (hence "typeDefs") | ||
// that together define the "shape" of queries that are executed against | ||
// your data. | ||
const typeDefs = (0, graphql_tag_1.default) ` | ||
# Comments in GraphQL strings (such as this one) start with the hash (#) symbol. | ||
# This "Book" type defines the queryable fields: 'title' and 'author'. | ||
type Book { | ||
title: String | ||
author: String | ||
} | ||
# The "GetBooksQuery" type is special: it lists all of the available queries that | ||
# clients can execute, along with the return type for each. In this | ||
# case, the "GetBooksQuery" query returns an array of zero or more Books (defined above). | ||
type Query { | ||
books: [Book] | ||
} | ||
`; | ||
const books = [ | ||
{ | ||
title: 'The Great Gatsby', | ||
author: 'F. Scott Fitzgerald', | ||
}, | ||
{ | ||
title: 'Wuthering Heights', | ||
author: 'Emily Brontë', | ||
}, | ||
]; | ||
// Resolvers define the technique for fetching the types defined in the | ||
// schema. This resolver retrieves books from the "books" array above. | ||
const resolvers = { | ||
Query: { | ||
books: () => books, | ||
}, | ||
}; | ||
// The ApolloServer constructor requires two parameters: your schema | ||
// definition and your set of resolvers. | ||
const server = new server_1.ApolloServer({ typeDefs, resolvers }); | ||
startStandaloneServer(server, { | ||
listen: { | ||
port: 4000, | ||
path: '/graphql', | ||
}, | ||
//@ts-ignore | ||
}).then((url) => { | ||
console.log(`🚀 Server ready at ${url.url}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GetBooksQuery = void 0; | ||
const client_1 = require("@apollo/client"); | ||
const graphql_tag_1 = __importDefault(require("graphql-tag")); | ||
const cross_fetch_1 = __importDefault(require("cross-fetch")); | ||
const client = new client_1.ApolloClient({ | ||
cache: new client_1.InMemoryCache(), | ||
link: new client_1.HttpLink({ uri: 'http://127.0.0.1:4000/graphql', fetch: cross_fetch_1.default }), | ||
headers: { | ||
foo: 'bar', | ||
}, | ||
}); | ||
function GetBooksQuery() { | ||
return client | ||
.query({ | ||
query: (0, graphql_tag_1.default) ` | ||
query GetBooksQuery { | ||
books { | ||
title | ||
author | ||
} | ||
} | ||
`, | ||
}) | ||
//@ts-ignore | ||
.then((result) => result.data); | ||
} | ||
exports.GetBooksQuery = GetBooksQuery; | ||
// For testing | ||
// GetBooksQuery().then(results => { | ||
// console.log(results); | ||
// }) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters