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

fix: Support Nexus 1.0.0 (#182) #183

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Support Nexus 1.0.0 (#182)
lewebsimple committed Dec 15, 2020
commit 80ae6d778305007b28dd85a0555473ebc5bb1a9d
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

## Overview

Nexus Shield is a [@nexus/schema](https://github.com/graphql-nexus/schema) plugin that helps you create an authorization layer for your application. It is a replacement for the provided authorization plugin. It is heavily inspired by [Graphql Shield](https://github.com/maticzav/graphql-shield) and reuses most of it's familiar ruling system. It takes full advantage of the type safety provided by nexus.
Nexus Shield is a [nexus](https://github.com/graphql-nexus/nexus) plugin that helps you create an authorization layer for your application. It is a replacement for the provided authorization plugin. It is heavily inspired by [Graphql Shield](https://github.com/maticzav/graphql-shield) and reuses most of it's familiar ruling system. It takes full advantage of the type safety provided by nexus.

## Install

2 changes: 1 addition & 1 deletion examples/complex/package.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
"start": "ts-node-dev --no-notify --transpileOnly --respawn src/server.ts"
},
"dependencies": {
"@nexus/schema": "^0.16.0",
"nexus": "^1.0.0",
"apollo-server": "^2.18.2",
"graphql": "^15.3.0",
"nexus-shield": "^1.1.1"
2 changes: 1 addition & 1 deletion examples/complex/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extendType, objectType, stringArg } from '@nexus/schema';
import { extendType, objectType, stringArg } from 'nexus';

import { chain, partial, ruleType } from 'nexus-shield';
import { isAuthenticated, isAdmin } from './rules';
2 changes: 1 addition & 1 deletion examples/complex/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { allow, nexusShield } from 'nexus-shield';
import { ApolloServer, ForbiddenError } from 'apollo-server';
import * as path from 'path';
import { makeSchema } from '@nexus/schema';
import { makeSchema } from 'nexus';

import * as types from './schema';
import { createContext } from './context';
2 changes: 1 addition & 1 deletion examples/simple/package.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
"start": "ts-node-dev --no-notify --transpileOnly --respawn src/server.ts"
},
"dependencies": {
"@nexus/schema": "^0.14.0",
"nexus": "^1.0.0",
"apollo-server": "^2.14.4",
"graphql": "^14.5.0",
"nexus-shield": "^1.0.7"
2 changes: 1 addition & 1 deletion examples/simple/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extendType, objectType, stringArg } from '@nexus/schema';
import { extendType, objectType, stringArg } from 'nexus';
import { ruleType } from 'nexus-shield';

export const Test = objectType({
2 changes: 1 addition & 1 deletion examples/simple/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { allow, nexusShield } from 'nexus-shield';
import { ApolloServer, ForbiddenError } from 'apollo-server';
import * as path from 'path';
import { makeSchema } from '@nexus/schema';
import { makeSchema } from 'nexus';

import * as types from './schema';

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
"object-hash": "^2.0.3"
},
"devDependencies": {
"@nexus/schema": "0.19.2",
"nexus": "1.0.0",
"@types/jest": "26.0.19",
"@types/node": "14.14.12",
"@types/object-hash": "1.3.4",
@@ -49,7 +49,7 @@
"typescript": "4.1.2"
},
"peerDependencies": {
"@nexus/schema": "^0.14.0 || ^0.15.0 || ^0.16.0 || ^0.17.0 || ^0.18.0 || ^0.19.0",
"nexus": "^1.0.0",
"graphql": "^14.5.0 || ^15.0.0"
},
"files": [
7 changes: 2 additions & 5 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { plugin } from '@nexus/schema';
import {
printedGenTyping,
printedGenTypingImport,
} from '@nexus/schema/dist/utils';
import { plugin } from 'nexus';
import { printedGenTyping, printedGenTypingImport } from 'nexus/dist/utils';
import * as hash from 'object-hash';

import { allow } from './builders';
6 changes: 3 additions & 3 deletions src/rules/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../config';
import {
@@ -28,7 +28,7 @@ export class BaseRule<TypeName extends string, FieldName extends string>
}

async resolve(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
@@ -56,7 +56,7 @@ export class BaseRule<TypeName extends string, FieldName extends string>
private cacheable(
key: string
): (
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo
6 changes: 3 additions & 3 deletions src/rules/interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../config';

@@ -27,7 +27,7 @@ export interface ShieldRuleOptions {

export interface ShieldRule<TypeName extends string, FieldName extends string> {
resolve(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
@@ -40,7 +40,7 @@ export type ShieldRuleFunction<
TypeName extends string,
FieldName extends string
> = (
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'>,
info: GraphQLResolveInfo
6 changes: 3 additions & 3 deletions src/rules/logic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../config';
import { ShieldContext, ShieldRule, ShieldRuleResult } from './interface';
@@ -16,7 +16,7 @@ export class LogicRule<TypeName extends string, FieldName extends string>
* By default logic rule resolves to false.
*/
async resolve(
_root: RootValue<TypeName>,
_root: SourceValue<TypeName>,
_args: ArgsValue<TypeName, FieldName>,
_ctx: GetGen<'context'> & ShieldContext,
_info: GraphQLResolveInfo,
@@ -29,7 +29,7 @@ export class LogicRule<TypeName extends string, FieldName extends string>
* Evaluates all the rules.
*/
async evaluate(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
4 changes: 2 additions & 2 deletions src/rules/operators/and.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../../config';
import { ShieldContext, ShieldRule, ShieldRuleResult } from '../interface';
@@ -17,7 +17,7 @@ export class RuleAnd<
* Makes sure that all of them have resolved to true.
*/
async resolve(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
6 changes: 3 additions & 3 deletions src/rules/operators/chain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../../config';
import { ShieldContext, ShieldRule, ShieldRuleResult } from '../interface';
@@ -17,7 +17,7 @@ export class RuleChain<
* Makes sure that all of them have resolved to true.
*/
async resolve(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
@@ -40,7 +40,7 @@ export class RuleChain<
* Evaluates all the rules.
*/
async evaluate(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
4 changes: 2 additions & 2 deletions src/rules/operators/not.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../../config';
import { ShieldContext, ShieldRule, ShieldRuleResult } from '../interface';
@@ -24,7 +24,7 @@ export class RuleNot<
*
*/
async resolve(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
4 changes: 2 additions & 2 deletions src/rules/operators/or.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../../config';
import { ShieldContext, ShieldRule, ShieldRuleResult } from '../interface';
@@ -17,7 +17,7 @@ export class RuleOr<
* Makes sure that at least one of them has evaluated to true.
*/
async resolve(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
6 changes: 3 additions & 3 deletions src/rules/operators/race.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsValue, GetGen, RootValue } from '@nexus/schema/dist/core';
import { GraphQLResolveInfo } from 'graphql';
import { ArgsValue, GetGen, SourceValue } from 'nexus/dist/core';

import { ShieldPluginOptions } from '../../config';
import { ShieldContext, ShieldRule, ShieldRuleResult } from '../interface';
@@ -17,7 +17,7 @@ export class RuleRace<
* Makes sure that at least one of them resolved to true.
*/
async resolve(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
@@ -42,7 +42,7 @@ export class RuleRace<
* Evaluates all the rules.
*/
async evaluate(
root: RootValue<TypeName>,
root: SourceValue<TypeName>,
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'> & ShieldContext,
info: GraphQLResolveInfo,
2 changes: 1 addition & 1 deletion tests/fixtures/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extendType, objectType } from '@nexus/schema';
import { extendType, objectType } from 'nexus';
import { AuthenticationError } from 'apollo-server';

import { ruleType } from '../../src';
2 changes: 1 addition & 1 deletion tests/fixtures/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeSchema } from '@nexus/schema';
import { makeSchema } from 'nexus';
import { ApolloServer, ForbiddenError } from 'apollo-server';
import * as path from 'path';

1,697 changes: 839 additions & 858 deletions yarn.lock

Large diffs are not rendered by default.