graphql-compose-mongoose icon indicating copy to clipboard operation
graphql-compose-mongoose copied to clipboard

Do you have any forum /mailing list /discord or slack channel for asking questions?

Open RageshAntony opened this issue 5 years ago • 3 comments

I need to learn more in this library

Do you have any forum /mailing list /gitter /discord or slack channel for asking questions?

RageshAntony avatar Oct 07 '20 07:10 RageshAntony

Nope, there is no online channel for asking questions. You may open issues with your questions in this repo if you have some.

nodkz avatar Oct 08 '20 10:10 nodkz

Nope, there is no online channel for asking questions. You may open issues with your questions in this repo if you have some.

I need to add relations in schema

the 'ref: 'User' ' is not working

In the docs , I can't understand the add releation method

Here my schema

const SeriesSchema = new mongoose.Schema({
  title: { type: String, required: true },
  description: { type: String, required: true },
  release: Date,
  language: String,
  seasons: Number,

  createdBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
  categoryId: { type: mongoose.Schema.Types.ObjectId, ref: 'Category' },

});
const CategorySchema = new mongoose.Schema({
  name: { type: String, required:true },
  discription: { type: String },
  category_img: { type: String },
});

......

import { SeriesTC } from '../models/series.model';

const SeriesQuery = {
    seriesById: SeriesTC.getResolver('findById'),
    seriesByIds: SeriesTC.getResolver('findByIds'),
    seriesOne: SeriesTC.getResolver('findOne'),
    seriesMany: SeriesTC.getResolver('findMany'),
    seriesCount: SeriesTC.getResolver('count'),
    seriesConnection: SeriesTC.getResolver('connection'),
    seriesPagination: SeriesTC.getResolver('pagination'),
};

const SeriesMutation = {
    seriesCreateOne: SeriesTC.getResolver('createOne'),
    seriesCreateMany: SeriesTC.getResolver('createMany'),
    seriesUpdateById: SeriesTC.getResolver('updateById'),
    seriesUpdateOne: SeriesTC.getResolver('updateOne'),
    seriesUpdateMany: SeriesTC.getResolver('updateMany'),
    seriesRemoveById: SeriesTC.getResolver('removeById'),
    seriesRemoveOne: SeriesTC.getResolver('removeOne'),
    seriesRemoveMany: SeriesTC.getResolver('removeMany'),
};


export { SeriesQuery, SeriesMutation };

Now my need is I need GraphQL query that have reference to User and Category Schema like this

query seriesById($_id: MongoID!){
    seriesById(_id: $_id){
        title
        description
        release
        language
        seasons
         
        categoryId {
          _id
         discription
         category_img
         }

        createdBy {
        ......
       }
    }
}

RageshAntony avatar Oct 11 '20 06:10 RageshAntony

You need to create all relations manually like in this test suite: https://github.com/graphql-compose/graphql-compose-mongoose/blob/master/src/tests/github_issues/263-test.ts#L31

And I recommend you use v9.0.0 with a new resolver creation approach

- const SeriesTC = composeWithMongoose(SeriesModel);
+ const SeriesTC = composeMongoose(SeriesModel);

const SeriesMutation = {
-    seriesCreateOne: SeriesTC.getResolver('createOne'),
+   seriesCreateOne: SeriesTC.mongooseResolvers.createOne(),
   ...
}

purpose of these changes described here https://github.com/graphql-compose/graphql-compose-mongoose/blob/master/docs/releases/9.0.0.md#a-new-way-for-resolver-creation-via-factory

Also in that article, you can find an example of how to create a relation via DataLoadar with Post & User.

nodkz avatar Oct 11 '20 13:10 nodkz