Skip to content

Commit

Permalink
refactor: rename app id to client id (#12)
Browse files Browse the repository at this point in the history
Renaming the parameter appId to clientId. Using client id will make it
more obvious to users what the value corresponds to in the Unsplash API,
as this should really be a layer on top of that API.

BREAKING CHANGE: appId is no longer supported and users will need to use
clientId for the same value.
  • Loading branch information
vacas5 authored Jun 13, 2024
1 parent 3472598 commit 4e5f823
Show file tree
Hide file tree
Showing 3 changed files with 570 additions and 569 deletions.
66 changes: 32 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@ Before using the Unsplash API, you need to [register as a developer](https://uns

```javascript
// In your gatsby-config.js
// Application id provided by Unsplash
// Client id refers to the access key provided by Unsplash
// Collections must be public to return photos
plugins: [
{
resolve: `gatsby-source-unsplash`,
options: {
appId: `12345678`,
collections: [
`098765`
],
clientId: `12345678`,
collections: [`098765`],
// optional: will only get page 1, so increase this count to include > 10 photos
perPage: `100`
perPage: `100`,
},
},
];
Expand All @@ -37,45 +35,45 @@ Get all photo urls in reverse chronological order with the photographer's name:

```graphql
query PhotosQuery {
allUnsplashPhoto(sort: { fields: [created_at], order: DESC }) {
edges {
node {
allUnsplashPhoto(sort: { fields: [created_at], order: DESC }) {
edges {
node {
id
user {
id
user {
id
name
}
urls {
full
regular
small
}
description
created_at
name
}
urls {
full
regular
small
}
description
created_at
}
}
}
}
```

Get a specific photo's urls by id with links to photographer's Unsplash profile:

```graphql
query PhotoQuery {
unsplashPhoto(id: { eq: "GnY_mW1Q6Xc" }) {
id
description
urls {
full
regular
small
}
user {
name
links {
html
}
}
unsplashPhoto(id: { eq: "GnY_mW1Q6Xc" }) {
id
description
urls {
full
regular
small
}
user {
name
links {
html
}
}
}
}
```
7 changes: 5 additions & 2 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ const Promise = require('bluebird');
const axios = require('axios');
const crypto = require('crypto');

exports.sourceNodes = ({ actions }, { appId, collections, perPage = 10 }) => {
exports.sourceNodes = (
{ actions },
{ clientId, collections, perPage = 10 }
) => {
const { createNode } = actions;
return Promise.all(
collections.map(collection => {
return axios
.get(`https://api.unsplash.com/collections/${collection}/photos`, {
params: {
client_id: appId,
client_id: clientId,
per_page: perPage,
},
})
Expand Down
Loading

0 comments on commit 4e5f823

Please sign in to comment.