-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e4008e
commit e52f8d5
Showing
8 changed files
with
61 additions
and
8 deletions.
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
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,3 @@ | ||
{ | ||
"presets": ["env"] | ||
} |
12 changes: 10 additions & 2 deletions
12
data-services/html-source/mimi-server--structured/README.md
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 |
---|---|---|
@@ -1,4 +1,12 @@ | ||
# This simple example performs the same functionality as the example found in ../mimi-server, but uses graphql-tools from Apollo | ||
# This simple example is the same as ../mimi-server but structured | ||
|
||
This is a fairly standard structure, with the schema and resolvers in to their own files. | ||
|
||
## Other changes from ../mimi-server | ||
|
||
### import and export instead of require | ||
|
||
[esm](https://www.npmjs.com/package/esm) is used to provide support for standard JavaScript import and export, which are not supported natively in node yet (as of 13.9). The `--experimental-support` flag could also be used if one does not want to use esm. | ||
|
||
|
||
See https://www.apollographql.com/docs/graphql-tools/ for documentation | ||
|
30 changes: 30 additions & 0 deletions
30
data-services/html-source/mimi-server--structured/collections.js
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,30 @@ | ||
const fetch = require('node-fetch'); | ||
import cheerio from 'cheerio'; | ||
|
||
|
||
const getCollections = async(kind) => { | ||
return fetch(`https://mimi.pnca.edu/f/${kind}`, {"credentials":"exclude","headers":{"accept":"text/html,application/xhtml+xml","accept-language":"en-US","cache-control":"no-cache","pragma":"no-cache"},"method":"GET"}) | ||
.then((response) => { | ||
return response.text() | ||
}).then((html) => { | ||
const collections = [] | ||
const $ = cheerio.load(html) | ||
$('a[data-no-turbolink="false"] h3').each(function (i, e) { | ||
const collectionsTitle = $(this).text(); | ||
if (collectionsTitle !== 'Collections') { | ||
const item = {} | ||
|
||
//TODO a bit of a hack parsing the html, which is prone to failure, add some checks on elements | ||
const style = $(this).parent().attr('style') | ||
const backgroundImage = style.indexOf("''") === -1 ? | ||
(style.split('background-image:url(\'')[1]).split('?')[0]: '' | ||
item['href'] = $(this).parent().parent().attr('href') | ||
item['backgroundImage'] = backgroundImage | ||
item['title'] = collectionsTitle.trim() | ||
collections.push(item); | ||
} | ||
}); | ||
return collections | ||
}) | ||
} | ||
export { getCollections } |
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
const { ApolloServer, gql } = require('apollo-server'); | ||
const fetch = require('node-fetch'); | ||
const cheerio = require('cheerio'); | ||
const { resolverMap } = require('./resolvers'); | ||
// const schema = require('schema'); | ||
import resolverMap from './resolvers'; | ||
import typeDefs from './schema'; | ||
|
||
const server = new ApolloServer({ typeDefs, resolvers: resolverMap }); | ||
|
||
server.listen().then(({ url }) => { | ||
console.log(`🚀 Server ready at ${url}`); | ||
}); |
5 changes: 5 additions & 0 deletions
5
data-services/html-source/mimi-server--structured/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { getCollections } from './collections' | ||
const resolverMap = { | ||
Query: { | ||
collections: async(_, args) => { | ||
|