Skip to content

Commit

Permalink
Generate Flow types of GraphQL queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
basilfx committed Jul 26, 2017
1 parent a30a416 commit cfbcc2b
Show file tree
Hide file tree
Showing 5 changed files with 350 additions and 69 deletions.
208 changes: 208 additions & 0 deletions photod-frontend/interfaces/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/* @flow */
// This file was automatically generated and should not be edited.

export type SearchMutationVariables = {|
query: string,
|};

export type SearchMutation = {|
search: ? {|
results: ? Array< {|
model: ?string,
pk: ?string,
score: ?number,
text: ?string,
|} >,
|},
|};

export type MediaFilesQueryVariables = {|
cursor?: ?string,
|};

export type MediaFilesQuery = {|
jobs: ? {|
edges: Array< {|
// The item at the end of the edge
node: ? {|
// The ID of the object.
id: string,
title: string,
progress: ?number,
items: ?number,
|},
|} >,
pageInfo: {|
// When paginating forwards, the cursor to continue.
endCursor: ?string,
// When paginating forwards, are there more items?
hasNextPage: boolean,
|},
|},
|};

export type AlbumsQueryVariables = {|
parentId?: ?string,
cursor?: ?string,
|};

export type AlbumsQuery = {|
albums: ? {|
edges: Array< {|
// The item at the end of the edge
node: ? {|
// The ID of the object.
id: string,
name: string,
|},
|} >,
pageInfo: {|
// When paginating forwards, the cursor to continue.
endCursor: ?string,
// When paginating forwards, are there more items?
hasNextPage: boolean,
|},
|},
|};

export type DirectoriesQueryVariables = {|
parentId?: ?string,
cursor?: ?string,
collapse?: ?boolean,
|};

export type DirectoriesQuery = {|
directories: ? {|
edges: Array< {|
// The item at the end of the edge
node: ? {|
// The ID of the object.
id: string,
fullPath: string,
name: string,
childrenCount: ?number,
totalChildrenCount: ?number,
mediaFilesCount: ?number,
totalMediaFilesCount: ?number,
|},
|} >,
pageInfo: {|
// When paginating forwards, the cursor to continue.
endCursor: ?string,
// When paginating forwards, are there more items?
hasNextPage: boolean,
|},
|},
|};

export type ProfileQuery = {|
me: ? {|
// The ID of the object.
id: string,
// Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.
username: string,
firstName: string,
lastName: string,
lastLogin: ?any,
dateJoined: any,
|},
|};

export type SharedQueryVariables = {|
cursor?: ?string,
|};

export type SharedQuery = {|
shares: ? {|
edges: Array< {|
// The item at the end of the edge
node: ? {|
// The ID of the object.
id: string,
mediaFile: {|
path: string,
|},
views: number,
created: any,
expires: ?any,
url: ?string,
|},
|} >,
pageInfo: {|
// When paginating forwards, the cursor to continue.
endCursor: ?string,
// When paginating forwards, are there more items?
hasNextPage: boolean,
|},
|},
|};

export type MediaFileFragmentFragment = {|
// The ID of the object.
id: string,
path: string,
name: ?string,
url: ?string,
mimeType: string,
fileSize: ?number,
width: ?number,
height: ?number,
duration: ?number,
orientation: ?number,
recorded: ?any,
created: any,
faces: ? {|
edges: Array< {|
// The item at the end of the edge
node: ? {|
// The ID of the object.
id: string,
x1: number,
y1: number,
x2: number,
y2: number,
person: ? {|
// The ID of the object.
id: string,
name: string,
|},
|},
|} >,
|},
palette: ? {|
edges: Array< {|
// The item at the end of the edge
node: ? {|
// The ID of the object.
id: string,
color: string,
prominence: number,
|},
|} >,
|},
thumbnails: ? {|
edges: Array< {|
// The item at the end of the edge
node: ? {|
// The ID of the object.
id: string,
width: number,
height: number,
url: ?string,
|},
|} >,
|},
filmstrips: ? {|
edges: Array< {|
// The item at the end of the edge
node: ? {|
// The ID of the object.
id: string,
width: number,
height: number,
url: ?string,
frames: number,
|},
|} >,
|},
|};
4 changes: 3 additions & 1 deletion photod-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "Photod",
"private": true,
"devDependencies": {
"apollo-codegen": "^0.15.2",
"babel-cli": "*",
"babel-core": "^6.25.0",
"babel-eslint": "*",
Expand Down Expand Up @@ -107,6 +108,7 @@
"start": "node_modules/.bin/webpack-dev-server --config webpack.config.js --port 8000 --progress --hot --inline",
"start-production": "NODE_ENV=production node_modules/.bin/webpack-dev-server --config webpack.config.production.js --port 8000 --progress --hot --inline",
"build": "NODE_ENV=production node_modules/.bin/webpack --config webpack.config.js --bail",
"build-production": "NODE_ENV=production node_modules/.bin/webpack --config webpack.config.production.js --bail"
"build-production": "NODE_ENV=production node_modules/.bin/webpack --config webpack.config.production.js --bail",
"build-schema": "apollo-codegen generate src/**/*.js --schema schema.json --target flow --output interfaces/schema.js"
}
}
2 changes: 0 additions & 2 deletions photod-frontend/src/pages/AlbumTreeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ const DirectoriesQuery = gql`
node {
id
name
childrenCount
mediaFilesCount
}
}
pageInfo {
Expand Down
58 changes: 0 additions & 58 deletions photod-frontend/src/pages/Directories.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,61 +113,3 @@ export default class Directories extends React.Component<DefaultProps, Props, St
);
}
}

/*
const DirectoriesQuery = gql`
query Directories($parentId: Int, $cursor: String) {
directories(first: 25, after: $cursor, parentId: $parentId) {
edges {
node {
id,
parentId,
path
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
`;
export default graphql(DirectoriesQuery, {
options: (props) => ({
variables: {
parentId: props.parentId,
},
}),
props({ data: { loading, directories, fetchMore } }) {
return {
loading,
directories,
hasNextPage: directories && directories.pageInfo.hasNextPage,
loadMoreEntries: (parentId) => {
return fetchMore({
variables: {
cursor: directories.pageInfo.endCursor,
},
updateQuery: (previousResult, { fetchMoreResult }) => {
if (!fetchMoreResult) {
return previousResult;
}
const newEdges = fetchMoreResult.directories.edges;
const pageInfo = fetchMoreResult.directories.pageInfo;
return {
directories: {
edges: [...previousResult.directories.edges, ...newEdges],
pageInfo,
},
};
},
});
},
};
},
})(Directories);
*/
Loading

0 comments on commit cfbcc2b

Please sign in to comment.