Skip to content

Commit

Permalink
Switch imageUrl to unsplash
Browse files Browse the repository at this point in the history
Fixes #107 #101
  • Loading branch information
IvanGoncharov committed May 27, 2020
1 parent 077d4b9 commit 682affd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/default-extend.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ extend type ___RootTypeName___ {

type Pet {
name: String @fake(type: firstName)
image: String @fake(type: imageUrl, options: { imageCategory: cats })
image: String @fake(type:imageUrl, imageKeywords: ["cats"] })
}
21 changes: 18 additions & 3 deletions src/fake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,24 @@ const fakeFunctions = {

// Image section
imageUrl: {
args: ['imageWidth', 'imageHeight', 'imageCategory', 'randomizeImageUrl'],
func: (width, height, category, randomize) =>
faker.image.imageUrl(width, height, category, randomize, false),
args: ['imageSize', 'imageKeywords', 'randomizeImageUrl'],
func: (size, keywords, randomize) => {
let url = 'https://source.unsplash.com/random/';

if (size != null) {
url += `${size.width}x${size.height}/`
}

if (keywords != null && keywords.length > 0) {
url += '?' + keywords.join(',');
}

if (randomize === true) {
url += '#' + faker.random.number()
}

return url;
},
},

// Internet section
Expand Down
25 changes: 6 additions & 19 deletions src/fake_definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,9 @@ enum fake__Types {
semver
}
enum fake__imageCategory {
abstract
animals
business
cats
city
food
nightlife
fashion
people
nature
sports
technics
transport
input fake__imageSize {
width: Int!
height: Int!
}
enum fake__loremSize {
Expand Down Expand Up @@ -177,11 +166,9 @@ input fake__options {
"Only for type \`money\`"
decimalPlaces: Int
"Only for type \`imageUrl\`"
imageWidth: Int
"Only for type \`imageUrl\`"
imageHeight: Int
"Only for type \`imageUrl\`"
imageCategory: fake__imageCategory
imageSize: fake__imageSize
"Only for type \`imageUrl\`. Example value: \`[\\"nature\\", \\"water\\"]\`."
imageKeywords: [String!]
"Only for type \`imageUrl\`"
randomizeImageUrl: Boolean
"Only for type \`email\`"
Expand Down

0 comments on commit 682affd

Please sign in to comment.