Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

SWAPI, Paging, DataLoader, Request ID #242

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Conversation

alexbal7
Copy link
Collaborator

No description provided.

Copy link
Contributor

@trioletas trioletas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an integration test. See joke test for reference (not e2e one)

@alexbal7
Copy link
Collaborator Author

Please add an integration test. See joke test for reference (not e2e one)

Added integration test.

src/connectors/swapi.ts Outdated Show resolved Hide resolved
};

/**
* Given a type, get the object with the ID.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function purpose can be easily derived from the name. does it make sense to rephrase the same in the comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not at all. Comments left during code port. Removed.

};

/**
* Given an objects URLs, fetch it, append the ID to it, sort it, and return it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort it

where?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed useless and incorrect comments (left from another project source code),

/**
* Given a type and ID, get the object with the ID.
*/
const byTypeAndId = async (type: string, id: string): Promise<Object> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await is kind of useless here, why not just

const byTypeAndId = async (type: string, id: string): Promise<Object> => getObjectFromTypeAndId(type, id)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored.

getObjectFromTypeAndId,
getObjectsFromType,
objectWithId,
} from '../../connectors/swapi';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To improve readability, I would suggest to import everything from the swapi connector and then just reference individual fns as such:

import * as swapi from '../../connectors/swapi';
....
const byTypeAndId = async (type: string, id: string): Promise<Object> =>
  // immediately clear that this model fn simply delegates to the connector module
  swapi.getObjectFromTypeAndId(type, id)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored.


objects = objects.concat(typeData.results.map(objectWithId));
while (nextUrl) {
// eslint-disable-next-line no-await-in-loop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed (left from another project source code).

@@ -4,11 +4,15 @@ import { Resolvers } from '../_generated/types';
import { query as Query } from './Query';
import { jokes as Jokes } from './Jokes';
import { joke as Joke } from './Joke';
import { node as Node } from './Node';

/** SWAPI resolvers */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.


const resolvers: Resolvers = {
Query,
Jokes,
Joke,
};

export default merge(resolvers);
export default merge(resolvers, swapiResolvers, { Node });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not spread over resolvers ?

const resolvers: Resolvers = {
 Query,
 Jokes,
 Joke,
...swapiResolvers,
{ Node }
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated TypeScript interface Resolvers does not contain SWAPI resolvers types.

import { importSchema } from 'graphql-import';

import resolvers from './resolvers';

const typeDefs: string = importSchema('src/graphql/schema/schema.graphql');
/** SWAPI schema */
import { swapiDef } from './schema/swapi';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please covert all ts schema files to graphql SDL (sorry)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not possible due to Relay connections. Please see ts schema files for details.

@alexbal7 alexbal7 changed the title SWAPI, Paging, DataLoader SWAPI, Paging, DataLoader, Request ID Jan 18, 2019
@alexbal7
Copy link
Collaborator Author

Added request id to logs.

@alexbal7 alexbal7 requested a review from aeldar January 18, 2019 10:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants