-
I've read the documentation on security but I'm still having trouble setting up the security policy. It seems like typescript expects the 'operationDomain' property in the security object, but I'm unsure of what to put there. Here's what I have so far: EntityManager setup new EntityManager({
mongodb: {
default: mongoDb
},
scalars: {
Date: { generate: () => new Date() },
},
security: {
context: {
permissions: {
'MANAGE_POSTS': [{ userId: 2}],
'VIEW_POSTS': true,
}
},
policies: {
post: {
permissions: {
MANAGE_POSTS: PERMISSION.ALLOW,
VIEW_POSTS: PERMISSION.READ_ONLY,
},
},
},
},
log: true,
})
import { gql } from 'graphql-tag'
export default gql`
scalar Date
scalar ID
type User @entity @mongodb {
id: ID! @id(from: "db") @alias(value: "_id")
firstName: String
lastName: String
birthDate: Date
posts: [Post!]! @foreignRef(refFrom: "userId")
permissions: [UserPermission!]!
}
type UserPermission {
userId: [ID!]
permission: Permission!
}
enum Permission {
VIEW_POSTS
MANAGE_POSTS
}
type Post @entity @mongodb {
id: ID! @id(from: "db") @alias(value: "_id")
userId: ID!
content: String
views: Int!
creationDate: Date!
}
` EDIT: I've looked into unit tests for typetta security and I've come up with a schema I'd like to use. However I'm unable to generate the scripts for this scheme. When I try to load this schema import { gql } from 'graphql-tag'
export default gql`
scalar Date
scalar Json
enum RoleCode {
SUPER_ADMIN,
MODERATOR,
USER
}
enum Permission {
CREATE_PROJECT,
DELETE_PROJECT,
UPDATE_PROJECT,
READ_PROJECT,
MANAGE_PROFILE,
READ_PROFILE,
}
type Role @entity @mongodb {
code: RoleCode! @id(from: "user")
permissions: [Permission]!
}
type User @entity @mongodb {
id: ID! @id(from: "db") @alias(value: "_id")
createdAt: Date!
email: String!
name: String
bannerLink: String
avatarLink: String
loginIdentities: [UserLoginIdentity!]! @foreignRef(refFrom: "userId")
socials: [UserSocial!]! @foreignRef(refFrom: "userId")
projectMembers: [ProjectMember!]! @foreignRef(refFrom: "userId")
roles: [UserRole!]! @foreignRef(refFrom: "userId")
}
type UserRole @entity @mongodb {
id: ID! @id(from: "db") @alias(value: "_id")
role: Role! @innerRef(refFrom: "roleCode", refTo: "code")
roleCode: RoleCode!
user: User! @innerRef
userId: ID!
}
type UserSocial @entity @mongodb {
id: ID! @id(from: "db") @alias(value: "_id")
name: String!
link: String!
user: User! @innerRef
userId: ID!
}
type UserLoginIdentity @entity @mongodb {
id: ID! @id(from: "db") @alias(value: "_id")
name: String!
data: Json
user: User! @innerRef
userId: ID!
}
type Project @entity @mongodb {
id: ID! @id(from: "db") @alias(value: "_id")
createdAt: Date!
updatedAt: Date!
completedAt: Date
name: String!
description: String!
cardImageLink: String
bannerLink: String
galleryImageLinks: [String!]!
soundcloudEmbedSrc: String
downloadLinks: [String!]!
members: [ProjectMember!] @foreignRef(refFrom: "projectId")
}
type ProjectMember @entity @mongodb {
id: ID! @id(from: "db") @alias(value: "_id")
name: String!
contributions: String!
roles: [ProjectMemberRole!]! @foreignRef(refFrom: "projectMemberId")
project: Project! @innerRef
projectId: ID!
user: User! @innerRef
userId: ID!
}
type ProjectMemberRole @entity @mongodb {
id: ID! @id(from: "db") @alias(value: "_id")
role: Role! @innerRef(refFrom: "roleCode", refTo: "code")
roleCode: Role!
member: ProjectMember! @innerRef
memberId: ID!
}
` I get the following error: Failed to load schema for "C:\Path\To\LearnTypetta\hello-world\src\generated\resolvers.ts"
Failed to load schema from src/generated/operations.ts,src/**.typedefs.ts:
Unknown type: "RoleCodeFilterInput".
Error: Unknown type: "RoleCodeFilterInput".
at getNamedType (C:\Path\To\LearnTypetta\hello-world\node_modules\graphql\utilities\extendSchema.js:360:13)
at getWrappedType (C:\Path\To\LearnTypetta\hello-world\node_modules\graphql\utilities\extendSchema.js:375:12)
at buildInputFieldMap (C:\Path\To\LearnTypetta\hello-world\node_modules\graphql\utilities\extendSchema.js:459:20)
at fields (C:\Path\To\LearnTypetta\hello-world\node_modules\graphql\utilities\extendSchema.js:642:22)
at resolveThunk (C:\Path\To\LearnTypetta\hello-world\node_modules\graphql\type\definition.js:480:40)
at defineInputFieldMap (C:\Path\To\LearnTypetta\hello-world\node_modules\graphql\type\definition.js:1208:18)
at GraphQLInputObjectType.getFields (C:\Path\To\LearnTypetta\hello-world\node_modules\graphql\type\definition.js:1155:27)
at collectReferencedTypes (C:\Path\To\LearnTypetta\hello-world\node_modules\graphql\type\schema.js:376:81)
at new GraphQLSchema (C:\Path\To\LearnTypetta\hello-world\node_modules\graphql\type\schema.js:148:9)
at Object.buildASTSchema (C:\Path\To\LearnTypetta\hello-world\node_modules\graphql\utilities\buildASTSchema.js:97:10)
GraphQL Code Generator supports:
- ES Modules and CommonJS exports (export as default or named export "schema")
- Introspection JSON File
- URL of GraphQL endpoint
- Multiple files with type definitions (glob expression)
- String in config file
Try to use one of above options and run codegen again.
at executeCodegen (C:\Path\To\LearnTypetta\hello-world\node_modules\@graphql-codegen\cli\index.js:1078:28)
at async generate (C:\Path\To\LearnTypetta\hello-world\node_modules\@graphql-codegen\cli\index.js:1388:25)
at async Command.exports.default (C:\Path\To\LearnTypetta\hello-world\node_modules\@twinlogix\typetta\lib\cli\generate\generate.js:145:17) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Can I see your |
Beta Was this translation helpful? Give feedback.
-
Hello, Two notes on your second GraphQL schema:
The problem is that with your typetta.yml the errors are not shown while with this one it does: schema: src/**.graphql
outputDir: src/generated
generateGraphQLOperations: false I'll try to understand why, thanks for reporting the problem. Let us know if you have any other issue. Edit: there is also a generation problem with enum types |
Beta Was this translation helpful? Give feedback.
-
With version 1.6.3-4 the problem should be fixed. Thank again for reporting the issue. |
Beta Was this translation helpful? Give feedback.
With version 1.6.3-4 the problem should be fixed. Thank again for reporting the issue.