accounts icon indicating copy to clipboard operation
accounts copied to clipboard

Graphql api context building changes

Open ozsay opened this issue 5 years ago • 6 comments

Hi,

The current graphql-api context builder (here) can only support graphql on regular apollo-server (that uses regular http server/express).

When we try to load accounts-server on apollo-server-lamda, the first parameter (session) is a different object than what is currently used in this package.

In this PR i changed the context factory to accept a requestExtractor function to extract info from the session.

@davidyaha @elie222 FYI

ozsay avatar Aug 20 '19 16:08 ozsay

Codecov Report

Merging #775 into master will increase coverage by 0.03%. The diff coverage is 72.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #775      +/-   ##
==========================================
+ Coverage   95.15%   95.18%   +0.03%     
==========================================
  Files          80       80              
  Lines        1774     1786      +12     
  Branches      348      350       +2     
==========================================
+ Hits         1688     1700      +12     
- Misses         78       79       +1     
+ Partials        8        7       -1
Impacted Files Coverage Δ
...raphql-api/src/modules/accounts/resolvers/query.ts 100% <100%> (ø) :arrow_up:
...i/src/modules/accounts-password/resolvers/query.ts 100% <100%> (ø) :arrow_up:
...hql-api/src/modules/accounts/resolvers/mutation.ts 92.3% <100%> (ø) :arrow_up:
...rc/modules/accounts-password/resolvers/mutation.ts 100% <100%> (ø) :arrow_up:
...graphql-api/src/modules/accounts-password/index.ts 72.22% <50%> (+3.47%) :arrow_up:
packages/graphql-api/src/modules/accounts/index.ts 77.77% <60%> (+1.77%) :arrow_up:
packages/graphql-api/src/utils/context-builder.ts 92.59% <92.85%> (+3.11%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update dca8132...cd02952. Read the comment docs.

codecov[bot] avatar Aug 21 '19 09:08 codecov[bot]

Codecov Report

Merging #775 into master will increase coverage by 0.03%. The diff coverage is 72.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #775      +/-   ##
==========================================
+ Coverage   95.15%   95.18%   +0.03%     
==========================================
  Files          80       80              
  Lines        1774     1786      +12     
  Branches      348      350       +2     
==========================================
+ Hits         1688     1700      +12     
- Misses         78       79       +1     
+ Partials        8        7       -1
Impacted Files Coverage Δ
...raphql-api/src/modules/accounts/resolvers/query.ts 100% <100%> (ø) :arrow_up:
...i/src/modules/accounts-password/resolvers/query.ts 100% <100%> (ø) :arrow_up:
...hql-api/src/modules/accounts/resolvers/mutation.ts 92.3% <100%> (ø) :arrow_up:
...rc/modules/accounts-password/resolvers/mutation.ts 100% <100%> (ø) :arrow_up:
...graphql-api/src/modules/accounts-password/index.ts 72.22% <50%> (+3.47%) :arrow_up:
packages/graphql-api/src/modules/accounts/index.ts 77.77% <60%> (+1.77%) :arrow_up:
packages/graphql-api/src/utils/context-builder.ts 92.59% <92.85%> (+3.11%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update dca8132...cd02952. Read the comment docs.

codecov[bot] avatar Aug 21 '19 09:08 codecov[bot]

i actually want to redesign it to make it more developer-friendly if possible. currently, it's alot of boilerplate to create a new module (for another authentication service).

I wonder if I should introduce breaking changes here, or create a new package

ozsay avatar Aug 22 '19 14:08 ozsay

What would be a breaking change?

davidyaha avatar Aug 22 '19 15:08 davidyaha

best case scenario, to create the graphql endpoint would be:

const graphqlModule = createAccountsGraphqlModule(accountsServer, requestExtractor, [
  {
    service: accountsPassword,
    typeDefs: accountsPasswordTypeDefs,
    resolvers: accountsPasswordResolvers
  },
  {
    service: accountsCode,
    typeDefs: accountsCodeTypeDefs,
    resolvers: accountsCodeResolvers
  }
]);

const apolloServer = new ApolloServer({
    typeDefs: graphqlModule.typeDefs,
    resolvers: graphqlModule.resolvers,
    context: graphqlModule.context,
  });

and for that, I need to change the graphql module creation and resolvers...

ozsay avatar Aug 22 '19 16:08 ozsay

Hello all. I was hoping to use Netlify functions to host my GraphQL API as a lambda but ran into issues to do with the context object not being set.

It would be great to see this PR merged into the next release along with an example of how to use it with apollo-server-lambda. Would this be possible?

gezquinndesign avatar Feb 16 '20 09:02 gezquinndesign

If this is still an issue please open a new PR for Accounts 1.0.

darkbasic avatar Nov 23 '23 09:11 darkbasic