Change fetched introspection with pregenerated one

pull/4/head
Max 4 years ago
parent b5a610f249
commit 45d8200cbb

@ -10,6 +10,6 @@ generates:
- "typescript-apollo-angular"
config:
immutableTypes: false
./graphql.schema.json:
src/generated/graphql.schema.json:
plugins:
- "introspection"

@ -38,7 +38,7 @@
"@angular/cli": "~10.0.8",
"@angular/compiler-cli": "~10.0.14",
"@graphql-codegen/cli": "^1.19.1",
"@graphql-codegen/introspection": "1.17.8",
"@graphql-codegen/introspection": "^1.17.8",
"@graphql-codegen/typescript": "1.17.8",
"@graphql-codegen/typescript-apollo-angular": "^2.1.0",
"@graphql-codegen/typescript-operations": "1.17.9",

@ -1,5 +1,4 @@
query GetCargoBikes {
...SchemaIntrospection
cargoBikes(limit: 100, offset: 0) {
...CargoBikeFields

@ -1,31 +0,0 @@
fragment GroupIntrospection on Query {
__type(name: "Group") {
name
enumValues {
name
}
}
}
fragment SchemaIntrospection on Query {
__schema {
types {
name
kind
enumValues {
name
}
fields {
name
type {
name
kind
ofType {
name
kind
}
}
}
}
}
}

@ -52,7 +52,6 @@ export class BikesService {
loadBikes() {
this.getCargoBikesGQL.fetch().subscribe((result) => {
this.bikes.next(result.data.cargoBikes);
this.schemaService.nextSchema(result.data.__schema);
});
}

@ -1,24 +1,19 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { find } from 'rxjs/operators';
import jsonSchema from 'src/generated/graphql.schema.json';
@Injectable({
providedIn: 'root',
})
export class SchemaService {
schema: BehaviorSubject<any> = new BehaviorSubject({});
nextSchema(schema: any) {
this.schema.next(schema);
}
/** expects startingObject and variablePath and returns its type e.g. cargoBike, security.name -> returns the type of the name variable */
getPropertyTypeFromSchema(
startingObjectName: String,
variable: String
): String {
startingObjectName: string,
variable: string
): string {
const variablePath = variable.split('.');
const types = this.schema.value.types;
const types = jsonSchema.__schema.types;
const startingObject = types.find(
(type) => type.name === startingObjectName
);
@ -27,19 +22,23 @@ export class SchemaService {
);
const type = field.type.name || field.type.ofType.name;
if (variablePath.length === 1) {
if ((field.type.kind === "ENUM")) {
return "Enum//" + this.getEnumValuesFromSchema(field.type.name).join("//");
if (field.type.kind === 'ENUM') {
return (
'Enum//' + this.getEnumValuesFromSchema(field.type.name).join('//')
);
}
return type;
} else {
return this.getPropertyTypeFromSchema(type, variablePath.slice(1).join('.'));
return this.getPropertyTypeFromSchema(
type,
variablePath.slice(1).join('.')
);
}
}
getEnumValuesFromSchema(typeName: String): String[] {
const types= this.schema.value.types;
const type = types.find(type => type.name === typeName);
getEnumValuesFromSchema(typeName: string): string[] {
const types = jsonSchema.__schema.types;
const type = types.find((type) => type.name === typeName);
return type.enumValues.map((value) => value.name);
}
}

File diff suppressed because it is too large Load Diff

@ -1668,167 +1668,6 @@ export enum CacheControlScope {
}
/** A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations. */
export type __Schema = {
__typename?: '__Schema';
description?: Maybe<Scalars['String']>;
/** A list of all types supported by this server. */
types: Array<__Type>;
/** The type that query operations will be rooted at. */
queryType: __Type;
/** If this server supports mutation, the type that mutation operations will be rooted at. */
mutationType?: Maybe<__Type>;
/** If this server support subscription, the type that subscription operations will be rooted at. */
subscriptionType?: Maybe<__Type>;
/** A list of all directives supported by this server. */
directives: Array<__Directive>;
};
/**
* The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum.
*
* Depending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name, description and optional `specifiedByUrl`, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types.
*/
export type __Type = {
__typename?: '__Type';
kind: __TypeKind;
name?: Maybe<Scalars['String']>;
description?: Maybe<Scalars['String']>;
specifiedByUrl?: Maybe<Scalars['String']>;
fields?: Maybe<Array<__Field>>;
interfaces?: Maybe<Array<__Type>>;
possibleTypes?: Maybe<Array<__Type>>;
enumValues?: Maybe<Array<__EnumValue>>;
inputFields?: Maybe<Array<__InputValue>>;
ofType?: Maybe<__Type>;
};
/**
* The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum.
*
* Depending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name, description and optional `specifiedByUrl`, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types.
*/
export type __TypeFieldsArgs = {
includeDeprecated?: Maybe<Scalars['Boolean']>;
};
/**
* The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum.
*
* Depending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name, description and optional `specifiedByUrl`, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types.
*/
export type __TypeEnumValuesArgs = {
includeDeprecated?: Maybe<Scalars['Boolean']>;
};
/** An enum describing what kind of type a given `__Type` is. */
export enum __TypeKind {
/** Indicates this type is a scalar. */
Scalar = 'SCALAR',
/** Indicates this type is an object. `fields` and `interfaces` are valid fields. */
Object = 'OBJECT',
/** Indicates this type is an interface. `fields`, `interfaces`, and `possibleTypes` are valid fields. */
Interface = 'INTERFACE',
/** Indicates this type is a union. `possibleTypes` is a valid field. */
Union = 'UNION',
/** Indicates this type is an enum. `enumValues` is a valid field. */
Enum = 'ENUM',
/** Indicates this type is an input object. `inputFields` is a valid field. */
InputObject = 'INPUT_OBJECT',
/** Indicates this type is a list. `ofType` is a valid field. */
List = 'LIST',
/** Indicates this type is a non-null. `ofType` is a valid field. */
NonNull = 'NON_NULL'
}
/** Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type. */
export type __Field = {
__typename?: '__Field';
name: Scalars['String'];
description?: Maybe<Scalars['String']>;
args: Array<__InputValue>;
type: __Type;
isDeprecated: Scalars['Boolean'];
deprecationReason?: Maybe<Scalars['String']>;
};
/** Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value. */
export type __InputValue = {
__typename?: '__InputValue';
name: Scalars['String'];
description?: Maybe<Scalars['String']>;
type: __Type;
/** A GraphQL-formatted string representing the default value for this input value. */
defaultValue?: Maybe<Scalars['String']>;
};
/** One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string. */
export type __EnumValue = {
__typename?: '__EnumValue';
name: Scalars['String'];
description?: Maybe<Scalars['String']>;
isDeprecated: Scalars['Boolean'];
deprecationReason?: Maybe<Scalars['String']>;
};
/**
* A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
*
* In some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.
*/
export type __Directive = {
__typename?: '__Directive';
name: Scalars['String'];
description?: Maybe<Scalars['String']>;
isRepeatable: Scalars['Boolean'];
locations: Array<__DirectiveLocation>;
args: Array<__InputValue>;
};
/** A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies. */
export enum __DirectiveLocation {
/** Location adjacent to a query operation. */
Query = 'QUERY',
/** Location adjacent to a mutation operation. */
Mutation = 'MUTATION',
/** Location adjacent to a subscription operation. */
Subscription = 'SUBSCRIPTION',
/** Location adjacent to a field. */
Field = 'FIELD',
/** Location adjacent to a fragment definition. */
FragmentDefinition = 'FRAGMENT_DEFINITION',
/** Location adjacent to a fragment spread. */
FragmentSpread = 'FRAGMENT_SPREAD',
/** Location adjacent to an inline fragment. */
InlineFragment = 'INLINE_FRAGMENT',
/** Location adjacent to a variable definition. */
VariableDefinition = 'VARIABLE_DEFINITION',
/** Location adjacent to a schema definition. */
Schema = 'SCHEMA',
/** Location adjacent to a scalar definition. */
Scalar = 'SCALAR',
/** Location adjacent to an object type definition. */
Object = 'OBJECT',
/** Location adjacent to a field definition. */
FieldDefinition = 'FIELD_DEFINITION',
/** Location adjacent to an argument definition. */
ArgumentDefinition = 'ARGUMENT_DEFINITION',
/** Location adjacent to an interface definition. */
Interface = 'INTERFACE',
/** Location adjacent to a union definition. */
Union = 'UNION',
/** Location adjacent to an enum definition. */
Enum = 'ENUM',
/** Location adjacent to an enum value definition. */
EnumValue = 'ENUM_VALUE',
/** Location adjacent to an input object type definition. */
InputObject = 'INPUT_OBJECT',
/** Location adjacent to an input object field definition. */
InputFieldDefinition = 'INPUT_FIELD_DEFINITION'
}
export type GetCargoBikeByIdQueryVariables = Exact<{
id: Scalars['ID'];
}>;
@ -1890,7 +1729,6 @@ export type GetCargoBikesQuery = (
{ __typename?: 'CargoBike' }
& CargoBikeFieldsFragment
)>> }
& SchemaIntrospectionFragment
);
export type BikeEventFieldsFragment = (
@ -1939,44 +1777,6 @@ export type CargoBikeFieldsFragment = (
& CargoBikeFieldsMutableFragment
);
export type GroupIntrospectionFragment = (
{ __typename?: 'Query' }
& { __type?: Maybe<(
{ __typename?: '__Type' }
& Pick<__Type, 'name'>
& { enumValues?: Maybe<Array<(
{ __typename?: '__EnumValue' }
& Pick<__EnumValue, 'name'>
)>> }
)> }
);
export type SchemaIntrospectionFragment = (
{ __typename?: 'Query' }
& { __schema: (
{ __typename?: '__Schema' }
& { types: Array<(
{ __typename?: '__Type' }
& Pick<__Type, 'name' | 'kind'>
& { enumValues?: Maybe<Array<(
{ __typename?: '__EnumValue' }
& Pick<__EnumValue, 'name'>
)>>, fields?: Maybe<Array<(
{ __typename?: '__Field' }
& Pick<__Field, 'name'>
& { type: (
{ __typename?: '__Type' }
& Pick<__Type, 'name' | 'kind'>
& { ofType?: Maybe<(
{ __typename?: '__Type' }
& Pick<__Type, 'name' | 'kind'>
)> }
) }
)>> }
)> }
) }
);
export type LendingStationFieldsGeneralFragment = (
{ __typename?: 'LendingStation' }
& Pick<LendingStation, 'id' | 'name'>
@ -2148,40 +1948,6 @@ export const CargoBikeFieldsFragmentDoc = gql`
${CargoBikeFieldsMutableFragmentDoc}
${ProviderFieldsGeneralFragmentDoc}
${LendingStationFieldsGeneralFragmentDoc}`;
export const GroupIntrospectionFragmentDoc = gql`
fragment GroupIntrospection on Query {
__type(name: "Group") {
name
enumValues {
name
}
}
}
`;
export const SchemaIntrospectionFragmentDoc = gql`
fragment SchemaIntrospection on Query {
__schema {
types {
name
kind
enumValues {
name
}
fields {
name
type {
name
kind
ofType {
name
kind
}
}
}
}
}
}
`;
export const GetCargoBikeByIdDocument = gql`
query GetCargoBikeById($id: ID!) {
cargoBikeById(id: $id) {
@ -2256,12 +2022,10 @@ export const UnlockCargoBikeDocument = gql`
}
export const GetCargoBikesDocument = gql`
query GetCargoBikes {
...SchemaIntrospection
cargoBikes(limit: 100, offset: 0) {
...CargoBikeFields
}
}
${SchemaIntrospectionFragmentDoc}
${CargoBikeFieldsFragmentDoc}`;
@Injectable({

@ -6,6 +6,7 @@
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"resolveJsonModule": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,

Loading…
Cancel
Save