当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript angular2-apollo.Angular2Apollo类代码示例

本文整理汇总了TypeScript中angular2-apollo.Angular2Apollo的典型用法代码示例。如果您正苦于以下问题:TypeScript Angular2Apollo类的具体用法?TypeScript Angular2Apollo怎么用?TypeScript Angular2Apollo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Angular2Apollo类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: LoginUser

 /**
  * @param user Credentials for the user to login.
  * @returns A promise wrapping the result from the loginUser mutation.
  */
 login(user: IScapholdUserInput): Promise<GraphQLResult> {
     return this.client.mutate({
         mutation: gql`
             mutation LoginUser($input: _LoginUserInput!) {
                 loginUser(input: $input) {
                     id
                     token
                 }
             }
         `,
         variables: {
             input: {
                 username: user.username,
                 password: user.password
             }
         }
     }).then((result: GraphQLResult) => {
         const {data, errors} = result;
         if (errors) {
             throw errors;
         }
         this.setCredential(data['loginUser']);
         this.syncUser(data['loginUser']['id']);
         return result;
     });
 }
开发者ID:scaphold-io,项目名称:angular2-apollo-client-webpack-starter,代码行数:30,代码来源:auth.service.ts

示例2: updateProfile

 updateProfile(firstName: string, lastName: string): Observable<ApolloQueryResult> {
   return  this.apollo
     .mutate({
       mutation: gql`
         mutation updateProfile(
           $firstName: String!
           $lastName: String!
         ) {
           updateProfile(
             firstName: $firstName
             lastName: $lastName
           ) {
             firstName
             lastName
           }
         }
       `,
       variables: {
         firstName,
         lastName
       },
     })
     .map(({ data }: ApolloQueryResult) => data.updateProfile)
     .catch(err => Observable.throw(err));
 }
开发者ID:correasebastian,项目名称:apollo-chat,代码行数:25,代码来源:profile.service.ts

示例3: loadSchema

 loadSchema() {
   return this.apolloClient.watchQuery(schemaQuery).map(({ data: { __schema } }) => {
     console.log(__schema);
     this.schema = __schema;
     return this.schema;
   });
 }
开发者ID:gaslight,项目名称:graphql-admin,代码行数:7,代码来源:schema_service.ts

示例4: GetUser

 syncUser(id: string): void {
     const subscription = this.client.watchQuery({
         query: gql`
             query GetUser($id: ID!) {
                 getUser(id: $id) {
                     id
                     username
                 }
             }
         `,
         variables: {
             id: id
         }
     }).subscribe({
         next: ((result: GraphQLResult) => {
             this.setUser(result.data['getUser']);
             subscription.unsubscribe();
         }).bind(this),
         error: ((error: Error) => {
             console.log(`Error getting user ${error.message}`);
             subscription.unsubscribe();
             throw error;
         }).bind(this)
     });
 }
开发者ID:scaphold-io,项目名称:angular2-apollo-client-webpack-starter,代码行数:25,代码来源:auth.service.ts

示例5: newUser

  /**
   * Create new user with type player.
   * @param user The user.
   */
  public newUser(user: User): Observable<User> {
    const token = this.login.getToken();
    if (!token) {
      return Observable.throw("No authentication token");
    }

    if (!this.connectivityService.isOnline()) {
      this.storeForLaterPush(user);
      return Observable.from([user]);
    }
    return this.apollo
      .mutate({
        mutation: gql`
          mutation newUser($token: String!, $user: AutoUser!) {
            viewer(token: $token) {
              createAutoUser(user: $user) {
                _id
              }
            }
          }
        `,
        variables: {
          token,
          user,
        },
      }).map(result => {
        return result.data.viewer.createAutoUser as User;
      });
  }
开发者ID:racketometer,项目名称:frontend-application,代码行数:33,代码来源:new-user.service.ts

示例6: CreateUser

 /**
  * @param user Credentials for the new user.
  * @returns A promise wrapping the result from the createUser mutation.
  */
 register(user: IScapholdUserInput): Promise<GraphQLResult> {
     return this.client.mutate({
         mutation: gql`
             mutation CreateUser($input: _CreateUserInput!) {
                 createUser(input: $input) {
                     changedUser {
                         id
                         username
                         createdAt
                         modifiedAt
                         lastLogin
                     }
                 }
             }
         `,
         variables: {
             input: {
                 username: user.username,
                 password: user.password
             }
         }
     }).then((result: GraphQLResult) => {
         const {data, errors} = result;
         if (errors) {
             throw errors;
         }
         this.setUser(data['createUser']['changedUser']);
         return result;
     });
 }
开发者ID:scaphold-io,项目名称:angular2-apollo-client-webpack-starter,代码行数:34,代码来源:auth.service.ts

示例7: ngOnInit

 ngOnInit() {
   this.author = this.apollo.watchQuery({
     query: getAuthorQuery
   })
     .subscribe(({data}) => {
       this.author = data.author;
     });
 }
开发者ID:kamilkisiela,项目名称:universal-starter-apollo,代码行数:8,代码来源:author.component.ts

示例8: getProfile

 getProfile(): Observable<ApolloQueryResult> {
   return this.apollo
     .watchQuery({
       query: gql`
         query getProfile {
           user {
             firstName
             lastName
           }
         }
       `
     })
     .map(({ data }: ApolloQueryResult) => data.user)
     .catch(err => Observable.throw(err));
 }
开发者ID:correasebastian,项目名称:apollo-chat,代码行数:15,代码来源:profile.service.ts

示例9: submitForm

  public submitForm(): void {
    if (!this.repoFullName) {
      return;
    }

    this.error = null;

    this.apollo.mutate({
      mutation: submitRepositoryMutation,
      variables: {
        repoFullName: this.repoFullName,
      },
    }).then(() => {
      this.router.navigate(['/feed/new']);
    }).catch((error) => {
      this.error = error.message;
    });
  }
开发者ID:Tallyb,项目名称:GitHunt-angular2,代码行数:18,代码来源:new-entry.component.ts

示例10: getUsers

 /**
  * Get users created by logged in user.
  */
 public getUsers(): Observable<Array<User>> {
   const token = this.login.getToken();
   if (!token) {
     return Observable.throw("No authentication token");
   }
   return this.apollo
     .query({
       query: gql`
         query getUsers($token: String!) {
           viewer(token: $token) {
             users {
               _id
               firstName
               lastName
               email
               allowSharing
               startedPlaying
               birthday
             }
           }
         }
       `,
       variables: {
         token,
       },
       forceFetch: true,
     }).catch((error, caught) => {
       console.error("UsersService.getUsers(): Error:", error);
       return caught;
     })
     .map(result => {
       return result.data.viewer.users.map((user) => {
         return new User(user);
       });
     });
 }
开发者ID:racketometer,项目名称:frontend-application,代码行数:39,代码来源:users.service.ts


注:本文中的angular2-apollo.Angular2Apollo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。