Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide function to transfer source type from one's resolver response to another resolver source inject #10

Open
aexol opened this issue Apr 21, 2024 · 0 comments

Comments

@aexol
Copy link
Contributor

aexol commented Apr 21, 2024

import { MongOrb, QuestionModel } from '@/src/orm.js';
import { createResolvers } from '@/src/axolotl.js';

export const Question = createResolvers({
  Question:{
    user: async ([source]) => {
      const questionSource = source as QuestionModel
      return MongOrb("User").collection.findOne({
        username: questionSource.user
      })
    }
  },
});

Normally we just import the type from some ORM and cast the type of source. But we can do better.

import { MongOrb, QuestionModel } from '@/src/orm.js';
import { createResolvers, fromSource } from '@/src/axolotl.js';
import { Query } from '@/src/axolotl.js';

export const Question = createResolvers({
  Question: fromSource(Query.questionById)({
    user: async ([source]) => {
      return MongOrb("User").collection.findOne({
// source is already typed
        username: source.user
      })
    }
  }),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant